How can you Change the image if your player has 2 Kill streak

so i have this this that when you have 2 Kill Streak in the Leaderboard You Change the image
This is the script i got so far`

Script

while true do
	local plr = game.Players.LocalPlayer
	local KillStreak = plr:WaitForChild("leaderstats"):WaitForChild("Kill Streak")
	if KillStreak == 2 then
		script.Parent.FrameKill.KillImage.Image = "http://www.roblox.com/asset/?id=8454083149"
	end
	wait()
end
2 Likes

Do killsteak.value for it to work see you didnt put that

1 Like

i am so dumb… i forgot to put value-
thanks

1 Like

The ‘while true do’ loop is questionable.

You already loaded the ‘leaderstats’, so why load ‘Kill Streak’ when the ‘leaderstats’ and the children of it are already loaded?

Here’s a script:

local Player = game:GetService("Players").LocalPlayer
local KillStreak = Player:WaitForChild("leaderstats"):FindFirstChild("Kill Streak")

if KillStreak.Value == 2 then
    script.Parent.FrameKill.KillImage.Image = "http://www.roblox.com/asset/?id=8454083149"
end
1 Like

i have this error
Players.CooingPizzaboy83.PlayerGui.KillAndDeathGui.ImageChanger:2: attempt to index nil with ‘WaitForChild’

i have this error whats wrong with it?
Players.CooingPizzaboy83.PlayerGui.KillAndDeathGui.ImageChanger:2: attempt to index nil with ‘WaitForChild’

Consider it changing to:

local Player = game:GetService("Players").LocalPlayer
local KillStreak = Player:FindFirstChild("leaderstats"):FindFirstChild("Kill Streak")

if KillStreak.Value == 2 then
    script.Parent.FrameKill.KillImage.Image = "http://www.roblox.com/asset/?id=8454083149"
end

now the error said
Players.CooingPizzaboy83.PlayerGui.KillAndDeathGui.ImageChanger:2: attempt to index nil with ‘FindFirstChild’

Note that the code should be in a LocalScript, you can’t get a LocalPlayer from using a server script.

Additionally, you can use the following in replacement of a loop.

KillStreak.Changed:Connect(function()
     -- if kill streak == 2 code here
end)
1 Like

thats not the problem

the problem is on this line

local KillStreak = Player:WaitForChild("leaderstats"):FindFirstChild("Kill Streak")

:man_facepalming: well, the error is because the player variable = nil (nothing), this means you didn’t retrieve the player correctly.

this means that the leaderstats thingy doesn’t exist as the error says

since the object doesn’t exist or nil, you can’t call any function of it

No, the Player doesn’t exist, that’s why the error is happening.
:WaitForChild() would start an infinite yield if it was not found, not an error.

so how can we make the script detect the player?

Is it a local script?

nope a normal script its not a localscript

Why are you trying to access the local player on a normal script?

Delete the old script, and make a local script with the following code:


local plr = game.Players.LocalPlayer
local KillStreak = plr:WaitForChild("leaderstats"):WaitForChild("Kill Streak")
if KillStreak == 2 then
	script.Parent.FrameKill.KillImage.Image = "http://www.roblox.com/asset/?id=8454083149"
end

KillStreak:GetPropertyChangedSignal('Value'):Connect(function()
      if KillStreak == 2 then
          script.Parent.FrameKill.KillImage.Image = "http://www.roblox.com/asset/?id=8454083149"
      end
end)
1 Like

it just said in the output
Infinite yield possible on ‘Players.CooingPizzaboy83:WaitForChild(“leaderstats”)’
even though there is one
image

Sorry to bring this topic again, you can’t access ‘LocalPlayer’ in a SERVER Script. You can only access ‘LocalPlayer’ in a LOCAL Script. So that explains why the Player variable is nil.

1 Like