So in my game I have a tool that will cause the server to anchor the player in place, play a sleeping animation or something, and then unanchor the player and do some stat changes.
Upon equipping the tool, I immediately force unequip it because I don’t want the player to be holding nothing (the tool is a invisible part). What i’m doing right now feels hacky, surely there’s a better way?
Instead of using the tool, couldn’t you just check for someone clicking on the screen?
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, processed)
if not processed then
if key.UserInputType == Enum.UserInputType.MouseButton1 or key.UserInputType == Enum.UserInputType.Touch or key.KeyCode == Enum.KeyCode.ButtonR2 then
game.ReplicatedStorage.Remotes.Rest:FireServer()
end
end
end)
In your code you are using game.ReplicatedStorage.Remotes.Rest:FireServer() but I think it should be game.ReplicatedStorage.Remotes.Rest:FireServer(script.Parent) - so that you can use that in a server script in your tool.
You are waiting for a frame - this is probably fine, but it would be better if you could use wait(1) instead, so that you don’t make the server wait any longer than you have to.
Overall I don’t think there’s much wrong here, but I would perhaps try to make it a bit more readable by using a bit more code and splitting it into multiple lines. This would make it easier to debug if something goes wrong. local tool = script.Parent
tool.Equipped:Connect(function()
game.ReplicatedStorage.Remotes.Rest:FireServer(tool)
wait(1)
game.Players.LocalPlayer.Character.Humanoid:UnequipTools()
end)