I have a local script inside StarterCharacterScripts, inside the script is a "onTouch" function... every time someone steps on a block that's in workspace, the local script will call out a FireServer(). The serverscript is supposed to get the information of the player who stepped on it and display their name on a surfaceGui, but this should only be for the player that stepped on it. But in game, when one person steps on it, the server script displays every player that's in the game's information. Has anyone ever experienced anything similar? I've been trying to search for a solution but I cant find anything!
--local script player=game.Players.LocalPlayer part.Touched:Connect(function(hit) game.ReplicatedStorage.brokenstuff.queueplayer:FireServer() end end) part.TouchEnded:Connect(function(hit) game.ReplicatedStorage.brokenstuff.unqueueplayer:FireServer() end) --server script(the script has more code in it but im not comfortable sharing it) function touched(player) local userId = player.UserId end function untouched(player) local userId = player.UserId end game.ReplicatedStorage.brokenstuff.queueplayer.OnServerEvent:Connect(touched) game.ReplicatedStorage.brokenstuff.unqueueplayer.OnServerEvent:Connect(untouched)
any help is appreciated! P.S. I don't get any errors
Like luccy already mentioned the Touched event already provides you the hit
part which touched your other part.
Knowing that any of the limbs of a character are directly below the model of the character you can indeed simply say hit.Parent
and that would be the character model.
Using that we can obtain the player who touched it using game.Players:GetPlayerFromCharacter(hit.Parent)
to find our player from the character model. If there's no player found this will simply return nil