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

How to make an item giver via a Player GUI?

Hey! I have been trying to make an item giver for my ROBLOX Game via a GUI.

This is my current code:

player = game.Players.LocalPlayer
item = game.ServerStorage["Teddy"]

script.Parent.MouseButton1Click:Connect(function()
    player:Clone().Parent = player.Backpack
end)

However, this didn't work.

How would you get around this?

1 answer

✓ Accepted answer

First of all, you're doing 2 things wrong here. Assuming that this is a Local Script, you can not access ServerStorage through client. (the name is ServerStorage for a reason)

If it's not a local script, then you're trying to use LocalPlayer inside a server script, which once again, is not possible.

Secondly, you're cloning the player into the players backpack? Don't really understand what you're trying to do.

Anyway, to fix this, make it a Local Script, put the item inside replicated storage, and do this :

local player = game.Players.LocalPlayer
local item = game:GetService('ReplicatedStorage')['Teddy']

script.Parent.MouseButton1Click:Connect(function()
    item:Clone().Parent = player.Backpack
end)

2 comments

0

Oh, I am so sleepy today. Thanks, this has solved my problem!

0

thats the exact code i was gonna type ;-;

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