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

touched event running on play? (part)

Asked by 3 years ago

so i have this problem where the .Touched event runs as soon as i press play, instead of waiting for the ball to touch it first. here's my script: (ignore the game.Workspace... twice, i had a bug where if i made it local something it would just affect the player instead)

local part = script.Parent

part.Touched:Connect(function(hit)
    local ball = hit.Parent:FindFirstChild("Ball")
    if ball then
        game.Workspace.Ball.Anchored = true
        game.Workspace.Ball.BrickColor = BrickColor.new("Gold")
    end
end)
0
Is this the whole script. If yes, what is the part and where is it located? Also, is the Ball in workspace and the ball is a sphere or a model? BestCreativeBoy 1395 — 3y
0
the part is just a basic part, located in the workspace. Realbluedrago 8 — 3y
0
the ball is a sphere in the workspace too Realbluedrago 8 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Well, according to your code, if any basic part or meshpart [which is not inside a model and in workspace], will trigger your .Touched event.

In order to fix, try the following code:

local part = script.Parent

part.Touched:Connect(function(hit)
    local ball = hit.Name -- Gets the name of the hitting part
    if ball == "Ball" then -- Checks if the name is Ball
        game.Workspace.Ball.Anchored = true
        game.Workspace.Ball.BrickColor = BrickColor.new("Gold")
    end
end)

Lemme know if it helps!

0
works perfectly, thank you! Realbluedrago 8 — 3y
Ad

Answer this question