Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Make CanCollide local in FE Server?

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.

5 comments

0

You could just use collisionGroups

0

you could use a remote event

0

Pedro another thing you could do is use a remoteevent and fireclient() to make the player do the change locally, as touched doesn't work from a local script.

0

This would be much easier to accomplish with local parts, since there would be a different part for each player. This would allow you to change the properties of that part so it only impacts certain players.

0

That's what I'm suggesting by using the remoteevent. Collisiongroups aren't difficult and are MUCH easier if you know how to use them, but you can't use Touched from a local script so you'd need remoteevents to tell the client to make it non collidable

2 answers

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.