You never defined "part", yet you used it. Instead, continue using script.Parent. That would make the script look like this:
debounce = true
script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil and debounce == true then
debounce = false
player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Parent.BrickColor = BrickColor.new("Really red")
if script.Parent.BrickColor == BrickColor("Really red") then
explosion = Instance.new("Explosion")
explosion.Position = script.Parent.Position
explosion.Parent = game.Workspace
script.Parent.BrickColor = BrickColor.new("Institutional white")
debounce = true
end
end
end)
or you could simply put another variable for part at the top to make it look like this (this would be the better solution):
debounce = true
part = script.Parent
part.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil and debounce == true then
debounce = false
player = game.Players:GetPlayerFromCharacter(hit.Parent)
part.BrickColor = BrickColor.new("Really red")
if script.Parent.BrickColor == BrickColor("Really red") then
explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.Parent = game.Workspace
part.BrickColor = BrickColor.new("Institutional white")
debounce = true
end
end
end)
The last thing that I noticed (which isn't an error, rather an unnecessary line of code), is that you defined the characters player, which you aren't using. If you aren't going to use this later on in the code, I suggest getting rid of it. Hope I helped.
-Cmgtotalyawesome
1 comment
also,
:Connectwith a lower "c" is deprecated, use:Connectwith an uppercase "c" or your scripts will soon all be broken.