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

I'm trying to make a GUI appear when you touch a brick, the output says this is the issue. Help?

Asked by 5 years ago
local p = script.Parent

p.Touched:Connect(function()
    game.ReplicatedStorage.WorldEvents.BoatShopEvent1:FireClient()
end)

p.TouchEnded:Connect(function()
    game.ReplicatedStorage.WorldEvents.BoatShopEvent2:FireClient()
end)

I don't understand what I did wrong, I was told I could fire remote events from the server to the client. I attempted this, and can't find the error.

0
This should most likely be a local script in which case you’d want OnClientEvent, but what is the function here? Who’s doing the touch? Where is the GUI stored? ABK2017 406 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

When you use :FireClient() from a server script, you need to define what player the server is gonna fire to in the arguments. If you dont, the server doesn't actually know what client to fire to and returns nil. I think you want to fire to the player that touched the brick, so you'd use :GetPlayerFromCharacter() to get the player.

local p = script.Parent

p.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then 
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)  
        if player then 
            game.ReplicatedStorage.WorldEvents.BoatShopEvent1:FireClient(player)
        end
    end
end)

-- I removed the TouchEnded event, since i really didnt think you wanted to fire twice. 
0
Greatly Appreciated!!! Bearturnedhuman 48 — 5y
Ad

Answer this question