Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

--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

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, Gameplayer365247v2 1055 — 5y
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! teeth3444444444 0 — 5y
Ad

Answer this question