I want it to make it delete parts that are named guard but instead it deletes other parts! How do i fix this?
function ds(hit)
if hit.Name ~= "Guard" then
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
I want it to make it delete parts that are named guard but instead it deletes other parts! How do i fix this?
function ds(hit)
if hit.Name ~= "Guard" then
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
Either like this..
function ds(hit)
if hit.Name ~= "Guard" then
--hit:Destroy()
else
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
or like this
function ds(hit)
if hit.Name == "Guard" then
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
Simple fix. Your script makes it so that parts that are not equal, or ~=, to “Guard” will be deleted. To fix this, just remove the tilde.
function ds(hit)
if hit.Name = "Guard" then
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
On line 2, you put "If hit.name = Guard then", what's wrong about that is this: "=". Basically "=" means not equal, since you put that there it will destroy everything that is not equal to "Guard". So basically it destroys everything that is not named "Guard". You can easily fix it by switching "=" to "==". Good luck making your game :)
function ds(hit)
if hit.Name == "Guard" then
hit:Destroy()
end
end
script.Parent.Touched:Connect(ds)
local Brick = script.Parent
function OnTouched(Hit)
if Hit.Name == "Guard" then
Hit:Destroy()
end
end
Brick.Touched:Connect(OnTouched)
Simple.
First of all you said if it is not named guard then destroy everything that is not named guard. It should look more like this.
01 function ds(hit)
02 if hit.Name == "Guard" then
03
04 hit:Destroy()
05
06
07 end
08
09
10 end
11 script.Parent.Touched:Connect(ds)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
It has a error on the equal but how
~= is for checking if [blank] is not equal to [blank]. == is for checking if [blank] is equal to [blank]. = is for telling the script that [blank] is equal to [blank]. >= is used when checking if a number is more than a different number. And <= is for checking if a number is less than a different number. The reason you get an error on the equals sign is because it should be two equals.