Tried to make a Destroy Function whenever the food is activated by a certain amount of times, it works and gets deleted on the Client, but its not deleting on the Server to which other players will now see that someone’s still carrying the Tool.
I tried to do remote events but I quickly realized, if one or more people has the same tool, it will affect other people’s tools and it will delete for them too.
Should I keep a standalone RemoteEvent inside the tool itself and a server script so that way it gets deleted both on the server and the client?
pls let me know which works best for this scenario thank you
Why are you making it both client and server based? Why not just one or the other?
What purpose does the client serve? Does it play animations? If not just port the entire script to the server and you won’t need any hacky work-arounds.
Also, even using remote events shouldn’t be that difficult. Tools are a descendant of the character, and remote events by default send the player over. You could just put the script in server script service and then read the tool from the player, and effect that specific tool.
local tool = player.Character and player.Character:FindFirstChildOfClass("Tool")
or player.Backpack:FindFirstChildOfClass("Tool") --// Backup state if tool isn't found on character, or if character doesn't exist
if not tool then return end
tool:Destroy
Alternatively just send over the tool name.
local tool = player.Character and player.Character:FindFirstChild(toolName)
or player.Backpack:FindFirstChild(toolName)
if not tool then return end
tool:Destroy()
Yes, you could unequip the tool on the client so that there isn’t latency to wait for the tool to disappear on the player’s side. However, you can’t delete the tool on the client so on the server you should delete it as well for the other player’s too so that it is replicated properly and can’t use the weapon incase. However, I’d reckon you should have one remote event and one server script managing the destruction of the tool so that in the future you don’t struggle with editing each script if you make any changes.
yes I’m making a animation for it so I had a local script for the animation. But I think I can work around with this one! I’ll go ahead and try it and see if it works. Thanks!
Just use any ONE of the THREE code samples I gave in a server script under ServerScriptService and a RemoteEvent in ReplicatedStorage. Neither should be under the tool, it’s poor optimization.
Out of the 3 samples, I’d recommend the second or third.
Remember that the first parameter passed through OnServerEvent is the player
yeah the third one seems to be the best in optimizing. I’ll make sure to use it, I really hate messy scripting so I have use Module Scripts to handle a lot lol
Make sure to perform sanity checks when using remote event, to avoid exploits and server crash by malicious individual. (Check if tool exist, its a typeof instance, its classname is “Tool”, it’s owned by the related player ect…)
remoteEvent.OnServerEvent:Connect(player, tool)
if tool ~= nil and typeof(tool) == "Instance" and tool:IsA("Tool") and (tool.Parent == player.Backpack or tool.Parent == player.Character) then
tool:Destroy()
end
end)