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

I need a part that cancollide = true if it's under 50 speed, and cancollide = false if it's over?

Asked by
cc0de 35
8 years ago

Basically it's designed for a vehicle, if the vehicle is going over 50 SPS, the part detects it and cancollide = false, and back to cancollide = true if it's under. Except this doesn't happen. What have I done wrong?

P = script.Parent
Player = game.Players.LocalPlayer
Human = Player.Character
Torso = Human.Torso


while true do
    wait(.05)
    local intSpeed = math.floor((Torso.Velocity.magnitude)/1.6)
    if Torso.Velocity >= 50  then P.CanCollide = false end
    if Torso.Velocity <= 50 then P.CanCollide = true end
end
0
I'm not entirely sure, but I don't believe you can have a greater than or equal to and less than or equal to correspoding to the same value. Example, if the speed is 50, what does the computer do? Should it allow collision or not? Again, not sure that's the problem. yoman1776 85 — 8y
0
All i need the script to do is make a part go cancollide = false if the LocalPlayer is going over 50 in a vehicle seat, and back to cancollide = true if under 50. cc0de 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

The problem is that you're using >= 50 AND <= 50 for both statements. You can't say that you want the part to be noncollide for players going 50+ and cancollide for players going 50- because if a player is going at 50 evenly the script won't know what to do. To fix this, you'll want to either change <= 50 to < 50(49-), or <= 49, like I did here:

P = script.Parent
Player = game.Players.LocalPlayer
Human = Player.Character
Torso = Human.Torso


while true do
    wait(.05)
    local intSpeed = math.floor((Torso.Velocity.magnitude)/1.6)
    if Torso.Velocity >= 50  then P.CanCollide = false end -- If the player is 50 or above the part is noncollide.
    if Torso.Velocity < 50 then P.CanCollide = true end -- If the player is below 50(49-) the part is cancollide.
end
0
Thanks for the attempt, but still nothing. I changed to transparency, instead of colliiding. cc0de 35 — 8y
Ad

Answer this question