OnClientEvent not working

So I’m trying to make a Tower of Hell win brick using a RemoteEvent but the LocalScript that receives the signal won’t do anything. I’m quite new to RemoteEvents and I haven’t really used them much.

Script in the win brick:

local Door = game.ReplicatedStorage:FindFirstChild("Door")
local TimerSpeed = game.ReplicatedStorage:FindFirstChild("TimerSpeed")
debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if not hit.Parent:FindFirstChild("Win") then
            if debounce == false then
                local player = game.Players:GetPlayerFromCharacter(hit.Parent)
                debounce = true
                wait()
                local Win = Instance.new("Weld")
                Win.Name = "Win"
                Win.Parent = hit.Parent

                TimerSpeed.Value = TimerSpeed.Value / 2
                player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value + 100
                Door:FireAllClients(player)
                print("All functions cleared")
                debounce = false
            end
        end
    end
end)

This script returns no errors but only a print as shown in one of the last lines
Screenshot 2020-06-19 at 11.40.24 am

LocalScript in Workspace receiving the RemoteEvent:

local TimerSpeed = game.ReplicatedStorage:FindFirstChild("TimerSpeed")
local Door = game.ReplicatedStorage:FindFirstChild("Door")
debounce = false

Door.OnClientEvent:Connect(function(player)
    if debounce == false then
        debounce = true
        print("Client received")
        wait()
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = player.Name.." has reached the top!"
        })
        TimerSpeed.Value = TimerSpeed.Value / 2
        wait(0.1)
        debounce = false
    end
end)

This LocalScript is supposed to send a message in the chat saying that the player has won, but this can only be done in a LocalScript and since the win brick requires a script to work I had to use a RemoteEvent.

I understand that I might’ve just made a simple mistake such as renaming the objects wrong. However I do appreciate support from the community so that I could improve on my future projects.

7 Likes

I think the player call not good, try to select the player on the Players.PLAYERNAME
Try this
game.Players:FindFirstChild(“NameHere”)

And, never trust the client
Also try to put your script in startPack not in workspace (the localscript)

2 Likes

Localscripts don’t run directly in workspace

4 Likes

So, put your local script in StarterPlayer > PlayerScript

5 Likes

Local scripts don’t run parented in the workspace environment. Try PlayerGui or StarterPlayerScripts. As the name implies, they are local to a player and in some form, this must show in the localscript’s ancestry.

5 Likes