Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is this event not being picked up by a script?

Asked by 3 years ago
Edited 3 years ago

Ok so I have a local script in a gui that when clicked it fires an event along with the data char which is the character of the player and is meant to be picked up by a script in serverscriptservice. HOWEVER while the local script fires the event and I know that it does because it prints out a confirmation the server doesnt pick up the event and doesnt do its part.

This is the local script:

local player = game.Players.LocalPlayer
local char = player.Character
function OnClicked() 
    print "Clicked"
    game.ReplicatedStorage.JoinedMap:FireServer(char)
    print "EventSent"
end 

script.Parent.MouseButton1Down:connect(OnClicked)

And this is the server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("JoinedMap")

local function JoinedMap(char)

    print "Event Recieved"

    char.Parent = game.Workspace.PlayersMap

    print "Set Parent"


    remoteEvent.OnServerEvent:Connect(JoinedMap)

end

Im so confused why isnt it getting picked up? It prints out "Clicked" and it prints out "EventSent "but the server does NOT print out "Event Received" nor does it print out "Set Parent"

0
Ive tried to move my entire game over to a new classic baseplate just to make sure no malicious script is running and still it doesnt work epicnmac 63 — 3y
0
This SHOULD work there is absolutely no reason this isn't working I just dont understand, my code should be working fine epicnmac 63 — 3y
0
lol djabdou33 40 — 3y

1 answer

Log in to vote
0
Answered by
Hypoxla 125
3 years ago
Edited 3 years ago

Try moving remoteEvent.OnServerEvent:Connect(JoinedMap) underneath end.

So:

local function JoinedMap(char)

    print "Event Recieved"

    char.Parent = game.Workspace.PlayersMap

    print "Set Parent"


end
    remoteEvent.OnServerEvent:Connect(JoinedMap)
0
tysm I didnt know that was the issue! epicnmac 63 — 3y
0
No problem! The reason why it wasn't working was because the remote event that was supposed to call the function was in the actual function itself. Hypoxla 125 — 3y
Ad

Answer this question