so i was tryna make it so when the tool is equipped the sword is equipped then when the tool is equipped again the the sword is unequipped
I think the issue is with the boolean for my other scripts the boolean item never seems to work, why?
local tool = script.Parent
tool.Equipped:Connect(function()
local hasToolEquiped = tool.hasToolEquiped
if hasToolEquiped.Value == true then
hasToolEquiped.Value = false
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local module = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local Name = script.Parent.KatanaName.Value
hum:UnequipTools()
module.WeaponUnEquip(player,Name)
end
if hasToolEquiped.Value == false then
hasToolEquiped.Value = true
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
print("works?")
local module = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local Name = script.Parent.KatanaName.Value
local WeaponEquipAnim = game:GetService("ReplicatedFirst").Animations.KatanaEquip
local loadEquipAnim = hum:LoadAnimation(WeaponEquipAnim)
loadEquipAnim:Play()
loadEquipAnim:GetMarkerReachedSignal("SpawnSwordEvent"):connect(function()
hum:UnequipTools()
module.WeaponEquip(player,Name)
end)
end
end)
yo bro its buggy, like when I first use it, it works, but then the second time I use it it bugs out, I’m trying to make it so that if sword = false then sword = true if sword = true then sword = false, not sure how to do this.
also I changed my script a but to make it so that its an input detection rather then a tool
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local module = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local Name = script.KatanaName.Value
local hasToolEquiped = script.hasToolEquiped
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.H then
if not hasToolEquiped.Value then
hasToolEquiped.Value = not hasToolEquiped.Value
print("this work?222")
module.WeaponUnEquip(player,Name)
end
if hasToolEquiped.Value then
hasToolEquiped.Value = not hasToolEquiped.Value
print("this work?")
local WeaponEquipAnim = game:GetService("ReplicatedFirst").Animations.KatanaEquip
local loadEquipAnim = hum:LoadAnimation(WeaponEquipAnim)
loadEquipAnim:Play()
loadEquipAnim:GetMarkerReachedSignal("SpawnSwordEvent"):connect(function()
hum:UnequipTools()
module.WeaponEquip(player,Name)
end)
end
end
end)
I think your script is bugging out because you have hasToolEquiped.Value = not hasToolEquiped.Value in both of the if statements. To fix it, try rearranging your code like this, so the line is after both of the if statements:
if not hasToolEquiped.Value then
-- not hasToolEquiped.Value code here
end
if hasToolEquiped.Value then
-- hasToolEquiped.Value code here
end
hasToolEquiped.Value = not hasToolEquiped.Value
yo bro
i tried the method of creating a boolen folder putting booleen into it when the player join
also tried just making a boolean in the script, like I got no idea why its happening
it still doesn’t work like when its true it will still run the if statement when it’s false
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local module = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local Name = script.KatanaName.Value
--local BooleanFolder = player:WaitForChild("BooleanFolder")
--local SwordEquip1 = BooleanFolder:WaitForChild("SwordEquip")
local SwordEquip = false
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.H then
if SwordEquip == true then
SwordEquip = false
print("this work?222")
module.WeaponUnEquip(player,Name)
end
if SwordEquip == false then
SwordEquip = true
print(SwordEquip)
print("this work?")
local WeaponEquipAnim = game:GetService("ReplicatedFirst").Animations.KatanaEquip
local loadEquipAnim = hum:LoadAnimation(WeaponEquipAnim)
loadEquipAnim:Play()
loadEquipAnim:GetMarkerReachedSignal("SpawnSwordEvent"):connect(function()
module.WeaponEquip(player,Name)
end)
end
end
end)
local user_input_service = game:GetService("UserInputService")
local cilent_player = game:GetService("Players").LocalPlayer
local character = cilent_player.Character
local humanoid = character:WaitForChild("Humanoid")
local WeaponModule = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local katana_name = script.KatanaName.Value
local bool_value = BooleanFolder:WaitForChild("SwordEquip") -- replace with your boolvalue
local sword_equipped = false
user_input_service.InputBegan:Connect(function(input_object, gpe)
if gpe then return end
if input_object.KeyCode == Enum.KeyCode.H then
if not bool_value.Value then
bool_value.Value = true
WeaponModule.WeaponUnEquip(cilent_player ,katana_name)
end
if bool_value.Value then
bool_value.Value = false
print(sword_equipped)
local WeaponEquipAnim = game:GetService("ReplicatedFirst").Animations.KatanaEquip
local loadEquipAnim = humanoid:LoadAnimation(WeaponEquipAnim)
loadEquipAnim:Play()
loadEquipAnim:GetMarkerReachedSignal("SpawnSwordEvent"):connect(function()
WeaponModule.WeaponEquip(cilent_player, katana_name)
end)
end
end
end)
You tried this and it didn’t work? I tried it and it printed correctly, so try the code and tell me if it still doesn’t work.
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local chr = player.Character
local hum = chr:WaitForChild("Humanoid")
local module = require(game:GetService("ReplicatedStorage").Modules.WeaponModule)
local Name = script.KatanaName.Value
local SwordEquip = false
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.H then
if SwordEquip == true then
print("this work?222")
module.WeaponUnEquip(player,Name)
end
if SwordEquip == false then
print("this work?")
local WeaponEquipAnim = game:GetService("ReplicatedFirst").Animations.KatanaEquip
local loadEquipAnim = hum:LoadAnimation(WeaponEquipAnim)
loadEquipAnim:Play()
loadEquipAnim:GetMarkerReachedSignal("SpawnSwordEvent"):connect(function()
module.WeaponEquip(player,Name)
end)
end
SwordEquip = not SwordEquip
end
end)