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 this work?

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

2 comments

0

Are you using a localscript?

0

In the future, please make the title of your question specific to your problem.

2 answers

✓ Accepted answer
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)

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

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