What do you want to achieve?
I want it so when you touch a part, YOU and only you will be chosen.
What is the issue?
It turns all the players in the server to the chosen thing and not the one who touched the part.
What solutions have you tried so far?
I looked on the dev forum but could not find anything the script is local so what is the problem?
script:
local part = workspace.ChangeIntoSimon
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players.LocalPlayer.Character
if player then
game.ReplicatedStorage["Chosen"]:FireServer(player)
end
end
end)
The script is a local script kept in StarterCharacterScripts.
Whenever you listen for the Touched event, every client is listening as well. Your code is set up very poorly, and needs restructuring. For one, you do not want any heavy deciding factors of your game dependent on the client. “Never trust the client.”
Instead, use a server script. Write the following code:
local part = workspace.ChangeIntoSimon
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
-- Execute code for "chosen" player.
end
end
end)
Unfortunately it still uses the touch event, as the client has some physics ownership on their end or some engine quirk it still gets exploited. The best that can be done from what I saw was a distance check with the touched event part.