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

Script runs automatically, ignores function event?

Asked by 6 years ago

I have a script where when someone walks on it, it will move to a specific spot, but when I boot up the game, it will completely ignore the touched function and automatically run the whole script.

local TweenService = game:GetService("TweenService")

local part = workspace.ManholeCover
part.Position = Vector3.new(-30.713, 285.446, -9.8)
part.Anchored = true
part.Parent = game.Workspace

 function MovePart()
local goal = {}
goal.Position = Vector3.new(-27.313, 285.446, -9.8)

local tweenInfo = TweenInfo.new(10)

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()
 end

workspace.ManholeCover.PartTouch.Touched:connect(MovePart)

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago

The Touched event fires when any other physical object touches the part in question. This means that as soon as you run the game, the manhole cover's Touched event is getting fired probably because of its surrounding parts and such. What you want to do is check if the part that touched the manhole cover is part of a player (assuming that's specifically want).

workspace.ManholeCover.PartTouch.Touched:Connect(function(hit)
    --hit is the other part that touched
    local player = game.Players.GetPlayerFromCharacter(hit.Parent)
    if player then
        MovePart()
    end 
end)
0
how would i correctly apply this into my script though? lolkid007 43 — 6y
Ad

Answer this question