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
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)
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
--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
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
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