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

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

Asked by 5 years ago
Edited 5 years ago

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.

0
If you would turn CanCollide false then the player would fall trough the map btw. Paintertable 171 — 5y
0
Yes, I realized that. It was just a typo in the title. I changed it. User#29793 0 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question