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

Why does this script not detect collisions correctly?

Asked by 10 years ago

This script is inside a brick that is one stud wide and a vehicle travelling at 60sps is going through that brick. This is meant to change the value in the vehicle yet it only does it some of the time, usually when going slower. (Rarely works on the first collision either)

I've tried making the brick longer but no luck. Can anyone see why?

Detector = script.Parent
enabled = true
BrickValue = 31

function onTouch(part)
    if not enabled then return end 
        enabled = false

        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        local human = part.Parent:findFirstChild("Humanoid") 
        if (human ~= nil) and player~= nil then 

            local bus = Workspace:FindFirstChild(player.Name.."'s Car")
            if bus:FindFirstChild("Fifteen")then
            bus.CurrentScore.Value = bus.CurrentScore.Value + BrickValue
            wait(3)              

        end 
        end
    wait()
    enabled = true 
end


Detector.Touched:connect(onTouch)
0
Collision detection are not very good at high speeds. You could always try a Ray Cast. hiccup111 231 — 10y
0
I could help because I did something similar to this.If you would like? HexC3D 830 — 10y

2 answers

Log in to vote
0
Answered by
Tesouro 407 Moderation Voter
10 years ago

You checked the player before the time.

Detector = script.Parent
enabled = true
BrickValue = 31

function onTouch(part)
    if not enabled then return end 
        enabled = false
        if part.Parent:findFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(part.Parent) then 
            local bus = Workspace:FindFirstChild(player.Name.."'s Car")
            if bus:FindFirstChild("Fifteen")then
            bus.CurrentScore.Value = bus.CurrentScore.Value + BrickValue
            wait(3)              

        end 
        end
    wait()
    enabled = true 
end


Detector.Touched:connect(onTouch)

But don't forget to look for an if statement that doesn't fit. Put some prints in each part and look the output.

0
That is my guess, I'm not sure. Tesouro 407 — 10y
0
It doesn't work at high speeds as hiccup111 said :/ Thanks for trying though :p MasterDaniel 320 — 10y
0
I don't see why, but ok. Tesouro 407 — 10y
Ad
Log in to vote
0
Answered by
KAAK82 16
10 years ago

just a few things to say, game.Players:GetPlayerFromCharacter() doesn't work... u need to give the system the Character not the Players to get the PlayerFromCharacter... also, u don't need if (this ~= nil) and anotherthing ~= nil then u don't need those Brackets :P

Answer this question