The issue is that my LocalScript doesn’t detect when the TextBouton is clicked.
How do I know it doesn’t detect?
because I use a Print(), and it doesn’t Print()
-- this is the content of my LocalScript
game.Players.PlayerAdded:Connect(function(player)
local playerLevel = player.leaderstats:WaitForChild("Level")
local shop = game.StarterGui:WaitForChild("Shop")
local primaryShopButton = shop:WaitForChild("PrimaryShopButton")
local frameLevel = script.Parent:WaitForChild("FrameLevel")
primaryShopButton.MouseButton1Down:Connect(function()
print("Click")
wait(.1)
for _, v in pairs(script.Parent:GetDescendants()) do
if v:FindFirstChild("Level") then
elseif v.Value >= playerLevel.Value then
frameLevel.Visible = false
else
frameLevel.Visible = true
end
end
end)
end)
This is because you’re using a local script w/ game.Players.PlayerAdded. That event simply doesn’t fire on a local script. Simply remove the “.PlayerAdded” event entirely, as the local script will automatically run right when the player joins.
local player = game.Players.LocalPlayer
local playerLevel = player.leaderstats:WaitForChild("Level")
local shop = game.StarterGui:WaitForChild("Shop")
local primaryShopButton = shop:WaitForChild("PrimaryShopButton")
local frameLevel = script.Parent:WaitForChild("FrameLevel")
primaryShopButton.MouseButton1Down:Connect(function()
print("Click")
wait(.1)
for _, v in pairs(script.Parent:GetDescendants()) do
if v:FindFirstChild("Level") then
elseif v.Value >= playerLevel.Value then
frameLevel.Visible = false
else
frameLevel.Visible = true
end
end
end)
There’s a possibility that one of your wait variables are producing infinite yield, and correct me if I’m wrong, but the script won’t continue if it’s waiting permanently.
Here is your problem. You are referencing StarterGui when you need to reference the player’s PlayerGui, which can be done by changing this variable to:
local shop = game.Players.LocalPlayer.PlayerGui:WaitForChild("Shop")
This error happens because Value isn’t a property of a Frame, which can be avoided by checking if it’s a frame or not and THEN running the line of code.
The elseif is causing the issue. Just remove the elseif and only write if. If it cant find the Level Object, then its trying to use v.Value which doesnt exist on a Frame.
new error that I really don’t understand
error "Value is not a valid member of Part “Players.YasinOfficiel.PlayerGui.Shop.PrimaryMainFrame.PrimarySafeArea.PrimaryItemFrame.Item1.VPF.PistolHandle”
I am finding the first child “Level” and its a Value, but the script is trying to get a value from the Parent (PistolHandle) of the “Level”
primaryShopButton.MouseButton1Down:Connect(function()
print("Click")
wait(.1)
for _, v in pairs(script.Parent:GetDescendants()) do
if v:FindFirstChild("Level") then
local player = game.Players.LocalPlayer
local playerLevel = player.leaderstats:WaitForChild("Level")
local playerGui = player:WaitForChild("PlayerGui")
local shop = playerGui:WaitForChild("Shop")
local primaryShopButton = shop:WaitForChild("PrimaryShopButton")
local frameLevel = script.Parent:WaitForChild("FrameLevel")
primaryShopButton.MouseButton1Down:Connect(function()
print("Click")
wait(.1)
for _, v in pairs(script.Parent:GetDescendants()) do
if v:FindFirstChild("Level") then
***if v.Value >= playerLevel.Value then***
frameLevel.Visible = false
else
frameLevel.Visible = true
end
end
end
end)