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

More than one person calling fire server when only one person calls it?

Asked by 5 years ago
Edited 5 years ago

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

0
Is there a reason you are trying to do it locally? You can get the person who stepped on a brick by getting the hit.Parent. royaltoe 5144 — 5y
0
I tottally forgot about that, thank you so much lucyy shootthegame 14 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question