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

How to make this work?

Asked by 9 years ago

Im trying to make a script where if you touch a torso of a player (no humanoid in it), it gives you Rum, but it says "tried to index player, a nil value?"

Script :

local player = game.Players.LocalPlayer
local money = player:WaitForChild("Money")

function onMouseClick(player)
    if player.money >= 3 then
        local Rum = game.Lighting:FindFirstChild("Rum")
        Rum:Clone()
        Rum.Parent = player.Backpack
    end
end

0
Are you using a localscript? Ryzox 220 — 9y
0
In the future, please make the title of your question specific to your problem. magiccube3 115 — 9y

2 answers

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago
script.Parent.MouseClick:connect(function(player) --because it's in clickdetector ;)
local money = player:findFirstChild("Money")
    if money.Value >= 3 then
        local Rum = game.Lighting:FindFirstChild("Rum")
        Rum:Clone()
        Rum.Parent = player.Backpack
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

You need a local script in order to reference game.Players.LocalPlayer or just commonly known as local player. You will just have to put this into a local script and put that local script into a directory that gets put into the local player

Answer this question