I wanted to touch and by doing so, destroy and explode another part. This is what I have done so far. The error message I get is
Script:5: attempt to index boolean with ‘Touched’. I’m guessing I did my boolean values but I know I’m missing something.
local TouchPad = script.Parent
local Block = game.Workspace
local TouchPad = false
TouchPad.Touched:Connect(function(hit)
if hit.Parent == character then
TouchPad = true
Block:Destroy()
local explosion =Instance.new('Explosion')
explosion.Position = part.Position
explosion.Parent = game.Workspace
end
end)
Yeah, you redefined TouchPad as boolean and it most likely is just overwriting it. Just change the name of the boolean so you have two different variables.
Also, are you trying to destroy the workspace or just something in it?
local TouchPad = script.Parent
local Block = game.Workspace --block is the workpace?
local TouchingPad = false
TouchPad.Touched:Connect(function(hit)
if hit.Parent == character then
TouchingPad = true
Block:Destroy()
local explosion =Instance.new('Explosion')
explosion.Position = part.Position
explosion.Parent = game.Workspace
end
end)
You associated Touch Pad as a boolean and as the parent of the script. Change one’s name so it makes sense, or else the script might be finding one of those variables and not the other.
That’s where I need help. I just want a character to be able to touch the TouchPad and make the Block explode and destroy it. I tried this and I get no errors but it also doesn’t work.
local TouchPad = script.Parent
local Block = workspace.Block
local TouchingPad = false
TouchPad.Touched:Connect(function(hit)
if hit.Parent == TouchPad then
TouchingPad = true
Block:Destroy()
local explosion =Instance.new('Explosion')
explosion.Position = Block.Position
explosion.Parent = game.Workspace
end
end)
ok, put this script inside of the touchPad and it will work.
local TouchPad = script.Parent
local blockToDestroy = game.Workspace.Part -- here put the part place
local isActivated = false
TouchPad.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and not isActivated then
isActivated = true
local explosion =Instance.new('Explosion')
explosion.Position = blockToDestroy.Position
explosion.Parent = game.Workspace
blockToDestroy:Destroy()
end
end)
Yes that worked thank you itsXtimes and everyone!! I also moved things around like the code below. This will destroy the Block but when I touch the TouchPad it will still continue to explode in the position of where the Block was even though it was destroyed. How can I modify my code to make it where it will only explode it once. I know the solution has been found but I need to learn about how the code would work in my original script. This should help me understand coding a bit more as I’m still a noob.
local TouchPad = script.Parent
local Block = workspace.Block
local TouchingPad = false
TouchPad.Touched:Connect(function(hit)
if hit.Parent == TouchPad then
TouchingPad = true
end
local explosion =Instance.new('Explosion')
explosion.Position = Block.Position
explosion.Parent = game.Workspace
Block:Destroy()
end)
you changed some things.
.Touched means everything that touches it,
so the part will always explode because the baseplate and other things are touching it,
so to fix it you can just use the code that I showed you…
if you want to change something just tell me
I was just trying to wrap my head around this part of the code
if plr and not isActivated then
So this is the part that allows the TouchPad to explode the Block once no matter how many times you touch the TouchPad afterward? And, on my original code,
if hit.Parent == TouchPad then
makes it where everything that touches it explode, right?
@spidermantom28
my code doing that if only the player touches the touchpad then will be an explosion 1 time
and then if you touch the touchpad again it wouldn’t do anything.
your code doing that if everything touching (so it will be touched every time because the terrain is always touching it) will make the explode and it can explode inf times.