So,
I have the script
Regular Script:
script.Parent.Touched:Connect(function(part) print("a") if part.Parent:FindFirstChild("Humanoid") then print("b") local char = part.Parent local plr = game.Players:GetPlayerFromCharacter(char) print(plr.Name) if plr:GetRankInGroup(2810845) > 5 then print("c") script.Parent.CanCollide = false end end end)
How do I make it so only the player who is allowed can walk trough? How to make the change local instead of global? Changing to local script does not work.
What you are attempting to do can easily be accomplished with local parts
. A local part
is a part that is only visible or interacted with by certain players. So you could essentially change the properties of this part to differ from the other players' part. Click here to learn more about local parts.
Note: Since local parts are not fully supported by Roblox, an update could be released at any moment that may break them.
Server script:
--Insert a remote event in ReplicatedStorage named 'AccessEvent' local AccessEvent = game.ReplicatedStorage:WaitForChild("AccessEvent") script.Parent.Touched:Connect(function(part) print("a") if part.Parent:FindFirstChild("Humanoid") then print("b") local char = part.Parent local plr = game.Players:GetPlayerFromCharacter(char) print(plr.Name) if plr:GetRankInGroup(2810845) > 5 then print("c") AccessEvent:FireClient(plr, script.Parent) --- fires to the targeted player and sends the part end end end)
Local script:
--Place this in StarterPlayerScripts located in the PlayerScripts folder local AccessEvent = game.ReplicatedStorage:WaitForChild("AccessEvent") AccessEvent.OnClientEvent:Connect(function(part) if part then part.CanCollide = false end end)