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

This script activates at the completely wrong time?!

Asked by 5 years ago
1local function partTouched(onTouch)
2    workspace.BossScript.Disabled = false
3    script.Parent:Destroy()
4end
5 
6script.Parent.Touched:Connect(partTouched)

this is my script. it enables BossScript which is disabled. but BossScript enables even if I dont touch it. and yes, i have checked if it is properly.

if you need the BossScript for some reason, probably not. but here

1game.ServerStorage.THEBoss.Parent = workspace
2local animation = workspace.THEBoss.Humanoid:LoadAnimation(workspace.THEBoss.Animation)
3animation:Play()

i knew that it was activated because i could see the boss in the background when testing

2 answers

Log in to vote
0
Answered by 5 years ago

Hello! There is a simple fix to this. So basically, if you want this script to check if a player touched it, then this is what you will have to do:

1local function Ontouch(hit) -- The hit is the object that the parent of this script has touched.
2    if game.Players:GetPlayerFromCharacter(hit.Parent) then --Basically checks if the owner of the hit is a player
3        workspace.BossScript.Disabled = false
4        script.Parent:Destroy()
5    end
6end
7script.Parent.Touched:Connect(Ontouch)

Your problem was that your function enabled when the brick that had that script in it, touched the baseplate, or some other objects. But, if you look at my script, I check that the hit.Parent == player. Hope It Helps

Ad
Log in to vote
0
Answered by 5 years ago

It's probably because it's touching another part. Instead you would want to say...

1local function partTouched(onTouch)
2        if onTouch.Parent:FindFirstChild('Humanoid') then
3            workspace.BossScript.Disabled = false
4            script.Parent:Destroy()
5    end
6end
7 
8script.Parent.Touched:Connect(partTouched)

Answer this question