Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script activates at the completely wrong time?!

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

✓ Accepted answer

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.