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

How to properly instantiate a tool to the player?

Asked by 4 years ago
Edited 4 years ago

I have a script that clones a tool (a pistol) from the ReplicatedStorage and puts it into the target player's Backpack. I can equip/unequip the item but it doesn't seem to work properly (the whole networking and basically working of the pistol scripts bug). If I otherwise put the tool in the Workspace, I can run over it, pick it up and be able to use it perfectly.

For example there's a sword that works perfectly when put directly in the Workspace and then the player runs over it, picks it up and uses it, but when instantiated from the ReplicatedStorage and put it in the Backpack directly it doesn't work.

My main goal is: I have a GUI inventory with weapon icons and when I click a weapon, the script instantiates the tool (weapon) into the player's backpack, but it doesn't work.

Is there something I am missing here? If you have any questions, please ask.

1 answer

Log in to vote
0
Answered by 4 years ago

lets say ur script to click the tool is inside a button then i think this script will help unless you already have done this local script:

script.Parent.MouseButton1Click:Connect(function()
local backpack = game.Players.LocalPlayer.Backpack
game.ReplicatedStorage:WaitForChild("event name"):FireServer(backpack)
end)

server script:

game.ReplicatedStorage:WaitForChild("event name").OnServerEvent:Connect(function(player,backpack)
game.ReplicatedStorage.toolname:Clone().Parent = backpack
end)

maybe you have done this, maybe not idk but it may help you, it just gets the players backpack from the local script over the event and puts the tool there

0
Genius! KaptonGames 11 — 4y
Ad

Answer this question