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

Help With Giver Script?

function oc()
	local sword = game.ReplicatedStorage.Sword:Clone()
	sword.Parent = game.Players.LocalPlayer.Backpack
end

script.Parent.ClickDetector.MouseClick:connect(oc)

When you click this button, it's supposed to give you a sword. It doesn't work, and it doesn't even bother to give me an error in the output.

2 comments

0

LocalScript I presume. You can not use LocalPlayer in a server script, and you can not use a LocalScript in a server object. The MouseClicked event does provide the player object who clicked on the brick, so you can utilize that when giving the object.

0

Oh ok, thanks.

1 answer

✓ Accepted answer

You probably already fixed this, but just answering so you can mark it as an accepted answer so that people wont look through this question thinking its unanswered.

The ClickDetector.MouseClick() function passes through the object which clicked it (only players because bricks dont have mouse cursors), which you can then use to give the tool to the player.

Example: function oc(player)

The (player) argument is the object which clicked on it. This can be renamed to anything, as it is just a variable.

Heres an example --v

function oc(player)
	local sword = game.ReplicatedStorage.Sword:Clone()
	sword.Parent = game.Players[player.Name].Backpack
end

script.Parent.ClickDetector.MouseClick:connect(oc)

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