local part = script.Parent local dummy = game.Workspace["Lost Soul"] local sound = script.Parent["Scary Jumpscare"] function Jumpscare() sound:Play() wait(1) dummy:Destroy() end part.Touched:Connect(Jumpscare)
When the part is touched, it is not specified what actually touched it.
For example,
local Part = game:GetService("Workspace"):WaitForChild("Part") Part.Touched:Connect(function(TouchedPart) --This will fire every time the part is touched even if it isn't the player end
We need to make sure its the Player touching the part and not some other random BasePart.
To ensure its the player we can do this:
local Players = game:GetService("Players") local Part = game:GetService("Workspace"):WaitForChild("Part") Part.Touched:Connect(function(TouchedPart) if Players:GetPlayerFromCharacter(TouchedPart.Parent) then --Do your code here end end
The reason this works is because GetPlayerFromCharacter() will return Nil if no Player can be associated with the Character, thus meaning an If-Then Statement will return false if no player can be found.