Hey all! Simple issue with probably a simple answer… Basically,
I have a particle emitter and a script.
The script will pick a random number (temp 0-10) and if its == 0 then it will enable the emitter. Here is the surprise, when the emitter enabled i was going to have everyone on the server receive a badge. (If fire flies are enabled people will get a badge for seeing them.
However, the script keeps on telling me Line 12 is nil.
(badgeservice:AwardBadge(char.UserID,badgeID)
Most of the numbers are temp but any help would be great.
here is the full code.
local player = game.Players.LocalPlayer
local badgeID = 2126443484
local badgeservice = game:GetService("BadgeService")
while wait(1)do
SpecialNumber = math.random(0,10)
if SpecialNumber == 0 then
script.Parent.ParticleEmitter.Enabled = true
local plr = game:GetService("Players")
local char = plr.LocalPlayer
badgeservice:AwardBadge(char.UserId,badgeID) -- This is line 12
print("Badge Awarded")
end
if SpecialNumber >= 1 then
script.Parent.ParticleEmitter.Enabled = false
end
print(SpecialNumber)
end
char variable are useless when your player variable have LocalPlayer, you can use player variable as replacement of line 12
edit: here the modified script
local player = game.Players.LocalPlayer
local badgeID = 2126443484
local badgeservice = game:GetService("BadgeService")
while wait(1)do
SpecialNumber = math.random(0,10)
if SpecialNumber == 0 then
script.Parent.ParticleEmitter.Enabled = true
-- delete another player variable, because at line 1, is already have (bug 1)
badgeservice:AwardBadge(player.UserId,badgeID) -- This is line 12, replace with the player variable in line 1
print("Badge Awarded")
end
if SpecialNumber >= 1 then
script.Parent.ParticleEmitter.Enabled = false
end
print(SpecialNumber)
end
local badgeID = 2126443484
local badgeservice = game:GetService("BadgeService")
game.Players.PlayerAdded:Connect(function(player)
while wait(1)do
SpecialNumber = math.random(0,10)
if SpecialNumber == 0 then
script.Parent.ParticleEmitter.Enabled = true
-- delete another player variable, because at line 1, is already have (bug 1)
badgeservice:AwardBadge(player.UserId,badgeID) -- This is line 12, replace with the player variable in line 1
print("Badge Awarded")
elseif SpecialNumber >= 1 then
script.Parent.ParticleEmitter.Enabled = false
end
print(SpecialNumber)
end
end)
sorry @msix29 , But PlayerAdded Now Change Into Function
local badgeID = 2126443484
local badgeservice = game:GetService("BadgeService")
local function onPlayerAdded(player)
-- The Script
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
there is no difference between our scripts, you made it as a separate function but i kept it as a single function, they will work in the same way though.
Yeah, imma have to figure it out that way then? Because sadly despite everyone’s help- it doesn’t work Dx. Do you know any good tutorials on how to fully understand and utilize remote events?
Step1: Put RemoteEvent in ReplicatedStorage and name it “AwardBadgeRemote”.
Step2: Put Script [NOT LOCAL] in ServerScriptService.
And code like:
local BadgeService = game:GetService("BadgeService")
local badgeId = 00000000 -- Replace to BadgeId
game.ReplicatedStorage.AwardBadgeRemote.OnServerEvent:Connect(function(player)
BadgeService:AwardBadge(player.UserId, badgeId)
end)
Step3: Put LocalScript in StarterGui.
Code:
local Player = game.Players.LocalPlayer
local ParticleEmitter = -- Locate to ParticleEmitte.
while task.wait(1) do
local SpecialNumber = math.random(1,10)
if SpecialNumber == 1 then
ParticleEmitter.Enabled = true
game.ReplicatedStorage.AwardBadgeRemote:FireServer()
print("Badge Awarded")
else
if SpecialNumber >= 2 then
ParticleEmitter.Enabled = false
end
print(SpecialNumber)
end
end
If this work, please mark this post as Solution. Thank you!
I see what you mean and it works! Thank you so much!!! and thank you to everyone else that helped, I really appreciate it. There are still certain aspects of LUA code i don’t understand xD.