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

How to give a tool to a certain type of player?

I was trying to give specified players a gravity coil when they entered the game. Here's the script:

local rs= game:GetService('ReplicatedStorage') --The Gravity Coil is in ReplicatedStorage by the way.
local plr = game.Players.LocalPlayer

game.Players.PlayerAdded:connect(function()
	
	local admins = (
		plr.UserId == 90568658 or
		plr.UserId == 76204529
	)	
	
	if admins then
		rs.GravityCoil:Clone().Parent = plr.StarterGear
		rs.GravityCoil:Clone().Parent = plr.Backpack
	end
end)

However, I got this error:

21:15:19.133 - Workspace.Script:7: attempt to index upvalue 'plr' (a nil value)

Please tell me what was wrong in the script or give me a link when there is a post with a similar problem.

2 comments

0

You never defined plr in the event. LocalPlayer can not be accessed via ServerScript.

0

do i have to put that into the LocalScript then?

1 answer

Not sure what the problem is with your script, but I edited it so it'll work. Put this in ServerScriptService or Workspace.

local rs= game:GetService('ReplicatedStorage')

local admins = {90568658,76204529}

game.Players.PlayerAdded:connect(function(Player) -- Once a player is added
	Player.CharacterAdded:connect(function() -- Once a character model is 
		for _,v in pairs(admins) do -- Gather all items in the table
			if Player.userId == v then -- Check if their a admin
				rs.GravityCoil:Clone().Parent = Player.Backpack -- Clone it
			end -- End the if statement
		end -- End the for _,v in pairs
	end) -- End the CharacterAdded
end) -- end the PlayerAdded

Sorry I can't really explain it any better.

4 comments

0

it didnt work. Heres another error: 21:39:18.503 - StarterGear is not a valid member of Player

0

Use WaitForChild() on the Player descendants. Also, userId is deprecated, use UserId.

0

on line what for the player descendants?

0

Player:WaitForChild('StarterGear') and Player:WaitForChild('Backpack'). Also, just a note, StarterGear does not work with FilteringEnabled for some reason (at least I thought that was a bug).

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