Text not changing and you cannot receive sword

Ok I want the text of the text button to change when the player is at level 5. But the text is not working and you cannot get the sword.

if game.Players.LocalPlayer.leaderstats.Kills.Value >= 5 then
         game.Players.LocalPlayer.PlayerGui.Shop.Sword1.Text = "Equip"
script.Parent.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end
1 Like

You need script.Parent.MouseButton1Click:Connect(function() under the end. And you have to use script.parent to change the text.

if game.Players.LocalPlayer.leaderstats.Kills.Value >= 5 then 
Script.Parent.Parent.Sword1.Text = "Equip"
end
end
script.Parent.MouseButton1Click:Connect(function()  
game.ReplicatedStorage.GetSword:FireServer("AzureSword",script.Parent)
end)

1 Like

For some reason, I tested it, but it didn’t work

Are there any errors? And you have to do the script on a local script if you haven’t.

You could do

game.Players.LocalPlayer.leaderstats.Kills.Changed:Connect(function()
if game.Players.LocalPlayer.leaderstats.Kills.Value >= 5 then
         game.Players.LocalPlayer.PlayerGui.Shop.Sword1.Text = "Equip"
script.Parent.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end
end)

If this fixes the problem then the problem was the code ran only one time but with the changed function everytime the value changes it runs to check if the value is equal 5

For some reason, it does not work

Can you show errors? 30 characters

It says shop is not a vaild member of playerGui

try this

--check when player's kills change
local Shop =  game.Players.LocalPlayer.PlayerGui:WaitForChild("Shop")
game.Players.LocalPlayer.leaderstats.Kills.Changed:Connect(function()
if game.Players.LocalPlayer.leaderstats.Kills.Value >= 5 then
         Shop.Sword1.Text = "Equip"
script.Parent.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end
end)
-- to check once the player enters 
if game.Players.LocalPlayer.leaderstats.Kills.Value >= 5 then
         Shop.Sword1.Text = "Equip"
script.Parent.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end

also can you send a screenshot of the stuff inside of StarterGui

i have recreated it in studio and it worked for me as i fixed some stuff as multiple errors where coming in

local Shop =  game.Players.LocalPlayer.PlayerGui:WaitForChild("Shop")
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local button = Shop.Sword1
local Kills = stats.Kills
Kills.Changed:Connect(function()
if Kills.Value >= 5 then
         Shop.Sword1.Text = "Equip"
button.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end
end)
-- to check once the player enters 
if Kills.Value >= 5 then
         Shop.Sword1.Text = "Equip"
button.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end

There is no error but the script dosent work


(Sorry for horrible handwriting)

Okay okay I get it now see the gui is not called shop but the frame is u should name the gui shop I will give the code in a sec

local Shop =  game.Players.LocalPlayer.PlayerGui:WaitForChild("Shop")
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local button = Shop.Shop.Sword1
local Kills = stats.Kills
Kills.Changed:Connect(function()
if Kills.Value >= 5 then
         Shop.Shop.Sword1.Text = "Equip"
button.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end
end)
-- to check once the player enters 
if Kills.Value >= 5 then
         Shop.Shop.Sword1.Text = "Equip"
button.MouseButton1Click:Connect(function()
       game.ReplicatedStorage.GetSword:FireServer("AzureSword", script.Parent)
end)
end

Very Important:
Change the Name of this Gui To Shop and change the script to the code i typed above

Well, again it didn’t work, but no errors in output or script analysis

what is your current code that you are using right now

@AmmarFreshYt code on his most recent post

Are you sure u changed the Name of the Gui To Shop

If you didn’t do it that is why it is not working