ive been going crazy for the past 2 hours
ive tried everything. global variables, normal variables, spreading it across many more scripts, but NOTHING is working
im trying to make a sword switch modes when you press q
localscript in the tool
local UID = game:GetService("UserInputService")
local ToolEquipped = false
script.Parent.Equipped:Connect(function()
ToolEquipped = true
end)
script.Parent.Unequipped:Connect(function()
ToolEquipped = false
end)
UID.InputBegan:Connect(function(key, typing)
if not typing then
if key.KeyCode == Enum.KeyCode.Q and ToolEquipped then
script.Parent.SwordSwitch:FireServer()
end
end
end)
it detects the q press just fine, and here’s my script for switching mode
serverscript in the tool
Mode = "Attack"
script.Parent.SwordSwitch.OnServerEvent:Connect(function(plr)
print("received")
if Mode == "Attack" then
Mode = "Knockback"
script.Parent.Handle.Color = Color3.fromRGB(0,0,255)
end
if Mode == "Knockback" then
Mode = "Heal"
script.Parent.Handle.Color = Color3.fromRGB(0,255,0)
end
if Mode == "Heal" then
Mode = "Attack"
script.Parent.Handle.Color = Color3.fromRGB(255,0,0)
end
end)
this is where ive been going crazy, it detects serverevent PERFECTLY FINE but for whatever reason MODE AND COLOR DONT CHANGE AND I CANT FIGURE OUT WHY
WHEN I PRINT MODE AND COLOR AFTER CHANGING THEM, IT SAYS THEYRE CHANGED BUT THEY REALLY ARENT AND IF I PRINT ANYWHERE ELSE IN THE SCRIPT IT ALSO SAYS IT ISNT CHANGED
i would really appreciate the help here because im genuinely losing my mind trying to figure this out ive been at this for 2 entire hours
So I don’t really know how to fix it since I’m not good at scripting tools,
but adding print statement’s to the script might make it easier to find the bugs.
But I wrote a script that will hopefully make it easier to find the bugs or fix the bug overall:
ServerScript:
local Mode = “Attack”
script.Parent.SwordSwitch.OnServerEvent:Connect(function(plr)
print(“received”)
if Mode == “Attack” then
print(“Mode Attack”)
Mode = “Knockback”
script.Parent.Handle.Color = Color3.fromRGB(0,0,255)
elseif Mode == “Knockback” then
print(“Mode Knockback”)
Mode = “Heal”
script.Parent.Handle.Color = Color3.fromRGB(0,255,0)
elseif Mode == “Heal” then
print(“Mode Heal”)
Mode = “Attack”
script.Parent.Handle.Color = Color3.fromRGB(255,0,0)
elseif not Mode then
print(“No Modes”)
end
end)
LocalScript look’s fine to me so I won’t add any changes there.
model boundary is kinda weird so the only way i did was to send the mode and had it checked in OnServerEvent
local UID = game:GetService("UserInputService")
local ToolEquipped = false
script.Parent.Equipped:Connect(function()
ToolEquipped = true
end)
script.Parent.Unequipped:Connect(function()
ToolEquipped = false
end)
UID.InputBegan:Connect(function(key, typing)
if not typing then
if key.KeyCode == Enum.KeyCode.Q and ToolEquipped then
script.Parent.SwordSwitch:FireServer("Attack") --send it as a string
end
end
end)
--inside server script
Mode = "Attack"
script.Parent.SwordSwitch.OnServerEvent:Connect(function(plr, actionz)
print("received")
if actionz == "Attack" then
Mode = "Knockback"
script.Parent.Handle.Color = Color3.fromRGB(0,0,255)
end
if actionz == "Knockback" then
Mode = "Heal"
script.Parent.Handle.Color = Color3.fromRGB(0,255,0)
end
if actionz == "Heal" then
Mode = "Attack"
script.Parent.Handle.Color = Color3.fromRGB(255,0,0)
end
end)