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

Why doesn't my code to make my player run into walls but not players work? Please help!

Here is my code:

local Player = game.Players.LocalPlayer

function HitByPlayer(ObjectTouched)
	if ObjectTouched == game.Players:GetChildren() then
		Player:GetChildren().CanCollide = false
	end
end

function HitByObject(ObjectTouched)
	if ObjectTouched ~= game.Players:GetChildren() then
		Player:GetChildren().CanCollide = true
	end
end

Player.Touched:Connect(HitByPlayer())
Player.Touched:Connect(HitByObject())

I am very new to Roblox Lua. So if this information I am going to give to you is fairly stupid, thats why. It is a Local Script. And it is also placed inside of the workspace. What I am trying to do is to switch your player's CanCollide to false when you run into another player and switch it to true when you run in to something that isn't a player. The code looks right to me. I don't know what is wrong. I hope you can find the solution. Thank you.

2 comments

0

If you would turn CanCollide false then the player would fall trough the map btw.

0

Yes, I realized that. It was just a typo in the title. I changed it.

1 answer

✓ Accepted answer

i would suggest using collision groups instead of trying to calculate using Touched events. read up more on those here.

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