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

Help With Giver Script?

Asked by
Scootakip 299 Moderation Voter
8 years ago
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.

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. M39a9am3R 3210 — 8y
0
Oh ok, thanks. Scootakip 299 — 8y

1 answer

Log in to vote
0
Answered by
joalars2 107
8 years ago

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

Answer this question