1 | local function partTouched(onTouch) |
2 | workspace.BossScript.Disabled = false |
3 | script.Parent:Destroy() |
4 | end |
5 |
6 | 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
1 | game.ServerStorage.THEBoss.Parent = workspace |
2 | local animation = workspace.THEBoss.Humanoid:LoadAnimation(workspace.THEBoss.Animation) |
3 | animation:Play() |
i knew that it was activated because i could see the boss in the background when testing
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:
1 | local 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 |
6 | end |
7 | 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...
1 | local function partTouched(onTouch) |
2 | if onTouch.Parent:FindFirstChild( 'Humanoid' ) then |
3 | workspace.BossScript.Disabled = false |
4 | script.Parent:Destroy() |
5 | end |
6 | end |
7 |
8 | script.Parent.Touched:Connect(partTouched) |