For some reason, the code fully runs but the actual unequipping of the tool does not happen. Does anyone know why?
--//SERVICES
local Players = game:GetService("Players")
--//REFRENCES
local Service = {}
function Service.Init()
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
StealingAttributeChange(plr)
end)
end)
end
function StealingAttributeChange(plr: Player)
plr:GetAttributeChangedSignal("IsStealing"):Connect(function()
local isStealing = plr:GetAttribute("IsStealing")
if isStealing == true then
print("IS STEALING")
local char = plr.Character
if not char then return end
forceUnEquip(char)
print("UNEQUIPPED")
end
end)
end
function forceUnEquip(char)
local hum = char:FindFirstChild("Humanoid")
if not hum then return end
hum:UnequipTools()
print("foreced unequip")
end
return Service
Are any of the print statements being reached? i’m not sure how to go about helping you without more information. It seems that you’re using a module script to unequip the tools, but that shouldn’t necessarily be an issue as Humanoid:UnequipTools() should replicate from the client.
this is a server script. Is that why? and yes all the prints are reached
I’m gonna go attempt to replicate this in studio, give me a couple minutes
have you tried moving the tool to the players backpack instead of using :UnequipTools
Alright let me know the results
will try that. Thank you for that suggestion
something like this?
--//SERVICES
local Players = game:GetService("Players")
--//REFRENCES
local Service = {}
function Service.Init()
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
StealingAttributeChange(plr)
end)
end)
end
function StealingAttributeChange(plr: Player)
plr:GetAttributeChangedSignal("IsStealing"):Connect(function()
local isStealing = plr:GetAttribute("IsStealing")
if isStealing == true then
print("IS STEALING")
local char = plr.Character
if not char then return end
reParentTool(plr)
print("UNEQUIPPED")
end
end)
end
function reParentTool(plr)
local tool = plr.Character:FindFirstChildOfClass("Tool")
if not tool then return end
tool.Parent = plr.Backpack
end
return Service
yep that worked. Just added a childAdded event function to the char and unequipped tool if my condition was met. Thanks