✓ Accepted answer
First, we have to put the localscript RainScript inside ServerStorage instead of StarterPlayerScripts. This is because any scripts inside StarterPlayerScripts will be moved to PlayerScripts once the player has joined the game, and the server cannot reference PlayerScripts.
Insert the following script inside the brick with the ClickDetector.
local players = game:GetService("Players")
local LegacyRainScript = game.ServerStorage:WaitForChild("RainScript")
local isRaining = false
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local ClonedRainScript = LegacyRainScript:Clone()
ClonedRainScript.Parent = Character
if isRaining then
ClonedRainScript.Disabled = false
end
end)
script.Parent.ClickDetector.MouseClick:Connect(function()
isRaining = true
for i, v in pairs(players:GetChildren()) do
if v.Character.RainScript then
v.Character.RainScript.Disabled = false
end
end
end)
If you would instead like the button to be able to toggle the rain on and off every time it's clicked for everybody, then replace it with this:
local players = game:GetService("Players")
local LegacyRainScript = game.ServerStorage:WaitForChild("RainScript")
local isRaining = false
game.Players.PlayerAdded:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local ClonedRainScript = LegacyRainScript:Clone()
ClonedRainScript.Parent = Character
if isRaining then
ClonedRainScript.Disabled = false
end
end)
script.Parent.ClickDetector.MouseClick:Connect(function()
isRaining = not isRaining
for i, v in pairs(players:GetChildren()) do
if v.Character.RainScript then
v.Character.RainScript.Disabled = not v.Character.RainScript.Disabled
end
end
end)