What this script is meant to achieve is to make a floor break under you (the trigger is placed above the break floor)
The problem is its being triggered by nothing at all… when playtesting it triggers as soon as the game loads in
I’ve tried moving other objects away moving it off the ground putting the code into a different part but it just triggers by nothing
Heres the code
function onTouched()
workspace.FloorTrap2.Transparency = 1
workspace.FloorTrap2.CanCollide = false
script.Parent[“Wood Breaking”].Playing = true
script:Destroy()
end
script.Parent.Touched:Connect (onTouched)
the thing is another part does the same thing and it works just fine
any suggestions?
Check if an actual player touched it. For example:
function onTouched(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
workspace.FloorTrap2.Transparency = 1
workspace.FloorTrap2.CanCollide = false
script.Parent[“Wood Breaking”].Playing = true
script:Destroy()
end
end
script.Parent.Touched:Connect(onTouched)
The game.Players:GetPlayerFromCharacter(hit.Parent)
uses a function of the Players service to get a player from the player’s character. If it finds a player with the parent of what touched it (which would be the character if it is a player), then it runs the code.
If you don’t have the
if game.Players:GetPlayerFromCharacter(hit.Parent) then
…line then it will activate the function whenever ANYTHING touches the part.
1 Like
Thanks!
I’m new to scripting and I guess I missed the binge reading developer.roblox.com
anyways you’re a life saver
2 Likes
Hope you keep going and meet your goals as a scripter!