ADVERTISEMENTREMOVE ADS

The Shattered Realms

Universal script
3 weeks ago
Script preview thumbnail
Script Preview

Description

The Shattered Realms

For Roblox studio lite

ADVERTISEMENTREMOVE ADS
126 Lines • 4.33 KiB
Raw
-- EventClient (robust version)
-- Place in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local EventFolder = ReplicatedStorage:WaitForChild("ShatteredRealmsEvent")
local RemoteEvent = EventFolder:WaitForChild("GlobalEventSignal")
-- Sound setup (per player)
local function makeEventMusic()
local sound = Instance.new("Sound")
sound.Name = "RealmMusic"
-- REPLACE the ID below with your chosen Sound ID
sound.SoundId = "rbxassetid://1846682446"
sound.Looped = true
sound.Volume = 0 -- start muted for fade-in
-- Parent into PlayerGui so it's local to the player
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
sound.Parent = playerGui
return sound
end
local eventMusic = makeEventMusic()
-- Create portal anchored near the player's character
local function spawnPortalNearCharacter(character)
if not character or not character:FindFirstChild("HumanoidRootPart") then return end
local hrp = character.HumanoidRootPart
local portal = Instance.new("Part")
portal.Anchored = true
portal.CanCollide = false
portal.Size = Vector3.new(8, 8, 1)
portal.Material = Enum.Material.Neon
portal.Color = Color3.fromRGB(120, 0, 255)
portal.Name = "EventPortal_" .. LocalPlayer.UserId
portal.CFrame = hrp.CFrame * CFrame.new(0, 0, -10)
portal.Parent = workspace
local particle = Instance.new("ParticleEmitter")
particle.Texture = "rbxassetid://258128463"
particle.Rate = 50
particle.Lifetime = NumberRange.new(2)
particle.Speed = NumberRange.new(2, 4)
particle.Rotation = NumberRange.new(0, 360)
particle.Size = NumberSequence.new({NumberSequenceKeypoint.new(0, 2), NumberSequenceKeypoint.new(1, 0)})
particle.Color = ColorSequence.new(Color3.fromRGB(160, 60, 255), Color3.fromRGB(60, 0, 120))
particle.Parent = portal
return portal
end
local activePortal = nil
local function fadeSound(sound, toVolume, timeSec)
timeSec = timeSec or 2
local tween = TweenService:Create(sound, TweenInfo.new(timeSec), {Volume = toVolume})
tween:Play()
end
local function startClientEvent()
print("[Client] Starting event for", LocalPlayer.Name)
if eventMusic and not eventMusic.IsPlaying then
eventMusic:Play()
fadeSound(eventMusic, 0.6, 2)
end
-- spawn portal when character exists
if LocalPlayer.Character then
activePortal = spawnPortalNearCharacter(LocalPlayer.Character)
end
-- ensure we spawn portal each time character respawns
LocalPlayer.CharacterAdded:Connect(function(char)
-- small delay to allow HRP to exist
task.wait(0.6)
if activePortal then
pcall(function() activePortal:Destroy() end)
end
activePortal = spawnPortalNearCharacter(char)
end)
-- quick atmospheric effect
local blur = Instance.new("BlurEffect", Lighting)
blur.Size = 24
task.wait(0.5)
TweenService:Create(blur, TweenInfo.new(1.5), {Size = 0}):Play()
task.wait(1.6)
if blur and blur.Parent then blur:Destroy() end
end
local function stopClientEvent()
print("[Client] Stopping event for", LocalPlayer.Name)
if eventMusic and eventMusic.IsPlaying then
fadeSound(eventMusic, 0, 1.5)
task.delay(1.6, function()
pcall(function() eventMusic:Stop() end)
end)
end
if activePortal then
pcall(function() activePortal:Destroy() end)
activePortal = nil
end
-- cleanup any leftover portals created earlier (safety)
for _, obj in pairs(workspace:GetChildren()) do
if typeof(obj.Name) == "string" and string.find(obj.Name, "EventPortal_") then
pcall(function() obj:Destroy() end)
end
end
end
RemoteEvent.OnClientEvent:Connect(function(action)
if action == "StartEvent" then
startClientEvent()
elseif action == "StopEvent" then
stopClientEvent()
end
end)
-- If server already active when client loads, server will have fired StartEvent earlier.
-- But to be safe, we can check on join by asking the server -- (optional).
ADVERTISEMENTREMOVE ADS

Comments

0 comments
to add a comment
Loading comments
ADVERTISEMENTREMOVE ADS