Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I fix my remote function to give the player their tool?

I made a giver that when you touch the part, a screen GUI appears. When the screen GUI appears I wanted it to fire a remote function to the server which then spawns the tool. I believe it has something to do with the Server script when the tool is supposed to spawn, but I'm not sure. I'm just trying to adjust after experimental mode was removed, any help would be appreciated!

--Local Script/Client 
script.Parent.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.O1TierEvent:FireServer()
end)

--Script/Server
game.ReplicatedStorage.O1TierEvent.OnServerEvent:Connect(function()
	local tool = script.Parent.OrangeswordTier1:Clone()
	tool.parent = game.Players.LocalPlayer.Backpack
end)

1 answer

✓ Accepted answer

--Local Script/Client

script.Parent.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.O1TierEvent:FireServer()
end)
game.ReplicatedStorage:WaitForChild("O1TierEvent").OnClientEvent:Connect(function(player,tool)
tool.Parent = player:WaitForChild("Backpack")
end)

--Script/Server

game.ReplicatedStorage.O1TierEvent.OnServerEvent:Connect(function()
    local tool = script.Parent.OrangeswordTier1:Clone()
game.ReplicatedStorage:WaitForChild("O1TierEvent"):FireClient(player,tool)
end)

the server script cant parent the tool to the players backpack since the backpack is on the client (your computer) so it needs to fire the client and then the client will pick this up and connect the tool function and then parent that clone as we created in the server script and parent it to the backpack also when you deal with remote events the best thing is to use :WaitForChild("event name here") just incase its lagging or something so we let the event load in before using it

2 comments

0

you might need to replace the player in the server script with something else since it needs to know which player it is, this is done with game.Players:GetPlayerFrom from the place here,

0

It works with "tool.Parent = player.Backpack" when you add player as an argument now. Although I see what you mean by doing ":WaitForChild". Thanks for the help!

This discussion is preserved as it was. New answers, comments, and votes are closed.