This is some script from the RemoteFunction and RemoteEvent tutorial on the wiki. I've followed all the instructions however it's still not working. I dont believe I'm missing anything... Please help
-- Inside Local Script local clickDetector = Instance.new("ClickDetector") clickDetector.Parent = game.Workspace.ColorBrick clickDetector.MouseClick:connect(function(hit) game.Workspace.MyServerEvent:FireServer() end)
-- Inside Server Script local event = Instance.new("RemoteEvent") -- creates the event object event.Parent = game.Workspace -- puts the event into the Workspace event.Name = "MyServerEvent" -- giving a name to the event so we can fire it specifically elsewhere event.OnServerEvent:connect(function() -- define the function that will be called when the event is fired -- this is where you put all the code you want to run when the event is fired game.Workspace.ColorBrick.BrickColor = BrickColor.Random() end)
Make sure the LocalScript is located somewhere in the player Character or in the Player object inside game.Players
You can also put the script in a tool. I prefer StarterPlayerScripts, I made the same mistake before, But i mostly solved it using a code:
Simple script that solved most of my problems:
local function scan(x) for i,v in ipairs(x:GetChildren()) do ---------------------------------------------------------------- if v:IsA("ClickDetector") and v.Parent:FindFirstChild("ClickEvent") then v.MouseClick:connect(function() v.Parent.ClickEvent:FireServer() end) end ---------------------------------------------------------------- if next(v:GetChildren()) ~= nil then scan(v) end end end scan(workspace)
And just put a RemoteEvent called "ClickEvent" on the same folder as the ClickDetector, and Change the script to
local clickEvent = script.Parent.ClickEvent clickEvent.OnServerEvent:connect(doSomething)