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 4 years ago
local function partTouched(onTouch)
    workspace.BossScript.Disabled = false
    script.Parent:Destroy()
end

script.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

game.ServerStorage.THEBoss.Parent = workspace
local animation = workspace.THEBoss.Humanoid:LoadAnimation(workspace.THEBoss.Animation)
animation: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 4 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:

local function Ontouch(hit) -- The hit is the object that the parent of this script has touched.
    if game.Players:GetPlayerFromCharacter(hit.Parent) then --Basically checks if the owner of the hit is a player
        workspace.BossScript.Disabled = false
        script.Parent:Destroy()
    end
end
script.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 4 years ago

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

local function partTouched(onTouch)
        if onTouch.Parent:FindFirstChild('Humanoid') then
            workspace.BossScript.Disabled = false
            script.Parent:Destroy()
    end
end

script.Parent.Touched:Connect(partTouched)

Answer this question