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)
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)