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 <= 49 then P.CanCollide = true end end
It looks like you may be mixing some server and client components of scripting. If the Part is the parent of the script then it would likely be a server Script
; however, the LocalPlayer
can only be used from a client LocalScript
.
I would suggest to make a LocalScript
and put it into StarterPlayerScripts
or StarterGui
. Next I'll make a few modifications to your code to put in the LocalScript
.
local P = game.Workspace.Part --change this to where the Part is located if this is not it local Player = game.Players.LocalPlayer local Torso = (Player.Character or Player.CharacterAdded:wait()):WaitForChild("Torso") -- waits until the character first spawns, yes it's a little complicated Player.CharacterAdded:connect(function(Character) -- gets the new Torso if the character respawns Torso = Character:WaitForChild("Torso") end) while true do wait(0.05) if Torso.Velocity.magnitude >= 50 then -- an if else statement is better to use than two if statements in this case P.CanCollide = false P.Transparency = 0.5 else P.CanCollide = true P.Transparency = 0 end end