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

Unknown global 'player' in a local script?

I'm trying to give a badge every time this function fires. I have one script and one localscript. It does not give me any indication of anything happening. I've been trying to fix this for a week now and I've practically given up.

Here is the script:

local Knock = script.Parent.Knock
local a = script.Parent
local knockbadgeEvent = game.ServerStorage.knockbadge

while true do
	wait(math.random(5,6))
	knockbadgeEvent:FireAllClients()
	Knock:Play()
	a.Material = "SmoothPlastic"
	script.Parent.SurfaceLight.Brightness = 0
	wait(.05)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.5
	wait(.05)
	a.Material = "SmoothPlastic"
	script.Parent.SurfaceLight.Brightness = 0
	wait(1.9)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.3
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 0.6
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 1
	wait(.4)
	a.Material = "SmoothPlastic"
	wait(.05)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.5
	wait(.05)
	a.Material = "SmoothPlastic"
	script.Parent.SurfaceLight.Brightness = 0
	wait(1.5)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.3
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 0.6
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 1
	wait(.5)
	a.Material = "SmoothPlastic"
	wait(.05)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.5
	wait(.05)
	a.Material = "SmoothPlastic"
	script.Parent.SurfaceLight.Brightness = 0
	wait(1.4)
	a.Material = "Neon"
	script.Parent.SurfaceLight.Brightness = 0.3
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 0.6
	wait(.1)
	script.Parent.SurfaceLight.Brightness = 1
end

And here is the localscript:

local badgeID = 2124476391
local bs = game:GetService("BadgeService")

local function onknockbadgeFired()
	bs:AwardBadge(player.UserId, badgeID)
end

I've tried defining player as game.Players.LocalPlayer but that doesn't work either!

3 comments

0

i dont see where the issue lies, how about showing the whole script(s)

0

k, but it's 58~ lines long lol

0

On line 1 type "repeat wait() until game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")"

1 answer

local player = game:GetService("Players").LocalPlayer

Add this to the LocalScript and player should then be defined.

1 comment

0

I did that and now it is defined, but the badge is still not being given out.

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