Local script problems

I’m very new to scripting and am not sure why this script isn’t working. I made it where when you say a certain phrase in chat something will happen. The thing is whenever I say the certain phrase in chat nothing happens and I am getting no errors.

Ok so too start I have a local script in StarterPlayerScripts:

local Block = game.ReplicatedStorage.Block:Clone()
local Rain = game.ReplicatedStorage.Rain:Clone()
local Cloud = game.ReplicatedStorage.Cloud:Clone()

Block.Parent = game.workspace.CurrentCamera
Rain.Parent = game.workspace.CurrentCamera
Cloud.Parent = game.workspace.CurrentCamera

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == "/e hello" then
			
			Block:Destroy()
			Rain:Destroy()
			Cloud.CloudPiece1.BrickColor = BrickColor.new("Pearl")
			Cloud.CloudPiece2.BrickColor = BrickColor.new("Pearl")
		    Cloud.CloudPiece3.BrickColor = BrickColor.new("Pearl")
	    end
	end)
end)

I think that’s all I have though, I just don’t know what I did wrong here. I think I might have to move it too ServerScriptService but I’m not too sure. Thanks

1 Like

This must be in a server script try putting this in a. Server Script in ServerScriptService, then it should work.

Also PlayerAdded is not available in local scripts

2 Likes

This event will only run on a normal script, on the server.

2 Likes

Can you try moving this script to StarterCharacterScripts?

2 Likes

Also this will not be executed

2 Likes

Alright, thank you.

I now have a local script in StarterPlayerScripts:

local Block = game.ReplicatedStorage.Block:Clone()
local Rain = game.ReplicatedStorage.Rain:Clone()
local Cloud = game.ReplicatedStorage.Cloud:Clone()

Block.Parent = game.workspace.CurrentCamera
Rain.Parent = game.workspace.CurrentCamera
Cloud.Parent = game.workspace.CurrentCamera

And also a script in ServerScriptService:

local Block = game.Workspace.Camera:WaitForChild("Block")
local Rain = game.Workspace.Camera.ReplicatedStorage.Rain
local Cloud = game.Workspace.Camera.ReplicatedStorage.Cloud

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == "/e hello" then

			Block:Destroy()
			Rain:Destroy()
			Cloud.CloudPiece1.BrickColor = BrickColor.new("Pearl")
			Cloud.CloudPiece2.BrickColor = BrickColor.new("Pearl")
			Cloud.CloudPiece3.BrickColor = BrickColor.new("Pearl")
		end
	end)
end)

It does end up giving me an error though. Am I doing something wrong still?

1 Like

You need to put everything you have in the local script into the server script, and completely remove the local script, this error is happening because you never added the variables into the server script

2 Likes