I've made a script that basically gives me two different abilities and modes when I press Z. It works at all, but when I press another key that isn't Z it spams the particles that appear in each mode. Can anyone recognize the reason?
local m = game.Players.LocalPlayer:GetMouse()
local character = game.Players.LocalPlayer.Character
local fire = "nou"
local ice = "nou"
db = true
m.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then
if script.Mode.Value == "" then
script.Mode.Value = "Ice"
elseif script.Mode.Value == "Ice" then
script.Mode.Value = "Fire"
elseif script.Mode.Value == "Fire" then
script.Mode.Value = ""
end
end
if script.Mode.Value == "Ice" then
--Attiva una variante
ice = "activated"
--Qui modifichi le vesti - Modify old clothes
script.Fire:Clone().Parent = character.LeftFoot
script.Fire:Clone().Parent = character.LeftHand
script.Fire:Clone().Parent = character.LeftUpperLeg
script.Fire:Clone().Parent = character.LeftUpperArm
--Rimuovi vecchie particelle - Remove old particles
if fire == "activated" then
character.RightFoot.Sparks:Destroy()
character.RightHand.Sparks:Destroy()
character.RightUpperLeg.Sparks:Destroy()
character.RightUpperArm.Sparks:Destroy()
character.RightFoot.Flame:Destroy()
character.RightHand.Flame:Destroy()
character.RightUpperLeg.Flame:Destroy()
character.RightUpperArm.Flame:Destroy()
end
-- Con questo attivi le mosse - Here you activate the abilities
print("Ice")
script.Parent.IceX.Disabled = false
script.Parent.FireX.Disabled = true
elseif script.Mode.Value == "Fire" then
-- Attiva una variante / N/A
fire = "activated"
--Qui modifichi le vesti - Here you modify clothes
script.Flame:Clone().Parent = character.RightFoot
script.Flame:Clone().Parent = character.RightHand
script.Flame:Clone().Parent = character.RightUpperLeg
script.Flame:Clone().Parent = character.RightUpperArm
script.Sparks:Clone().Parent = character.RightFoot
script.Sparks:Clone().Parent = character.RightHand
script.Sparks:Clone().Parent = character.RightUpperLeg
script.Sparks:Clone().Parent = character.RightUpperArm
--Rimuovi vecchie particelle - Remove old particles
if ice == "activated" then
character.LeftFoot.Fire:Destroy()
character.LeftHand.Fire:Destroy()
character.LeftUpperLeg.Fire:Destroy()
character.LeftUpperArm.Fire:Destroy()
end
-- Con questo attivi le mosse - Active the abilities
print("Fire")
script.Parent.IceX.Disabled = true
script.Parent.FireX.Disabled = false
elseif script.Mode.Value == "" then
-- Qui modifichi le vesti / Here you modify the clothes
if fire == "activated" then
character.RightFoot.Sparks:Destroy()
character.RightHand.Sparks:Destroy()
character.RightUpperLeg.Sparks:Destroy()
character.RightUpperArm.Sparks:Destroy()
character.RightFoot.Flame:Destroy()
character.RightHand.Flame:Destroy()
character.RightUpperLeg.Flame:Destroy()
character.RightUpperArm.Flame:Destroy()
print("Test")
-- Qui togli le mosse - You deactivate the abilities
script.Parent.IceX.Disabled = true
script.Parent.FireX.Disabled = true
end
end
end)

1 comment
KeyDown is deprecated so you should use UserInputServiceInstead.