local Tool = script.Parent
local Plr = game.Players.LocalPlayer
local Used = false
Tool.Activated:Connect(function()
local Hunger = Plr.PlayerGui:WaitForChild("HungerVal")
if not Used then
Used = true
Hunger.Value = Hunger.Value + 40
if Hunger.Value > 100 then
Hunger.Value = 100
end
wait(0.5)
script.Parent.Handle.Eat:Play()
wait(0.5)
Tool:Destroy()
end
end)
Here is a local script for a food tool, at the end the tool gets destroyed, but this seems to do it only locally, and other players can still see the tool in the players hand even though it doesnt exist for them anymore. How should I go about solving this?
You would want to have a server script with a remote event as a child additionally to the client script inside the tool, from the client script you want to fire the server script’s RemoteEvent. On the server script you put inside the tool, youll wait for the remote event to fire and then destroy the tool.
Server script inside the tool:
local Tool = script.Parent
local Event = Instance.new("RemoteEvent",script)
Event.OnServerEvent:Once(function()
Tool:Destroy()
end)
The client script should look something like this:
local Tool = script.Parent
local Plr = game.Players.LocalPlayer
local Used = false
Tool.Activated:Connect(function()
local Hunger = Plr.PlayerGui:WaitForChild("HungerVal")
if not Used then
Used = true
Hunger.Value = Hunger.Value + 40
if Hunger.Value > 100 then
Hunger.Value = 100
end
wait(0.5)
script.Parent.Handle.Eat:Play()
wait(0.5)
Tool.Script.RemoteEvent:FireServer()
end
end)