I’m not sure how to explain it in the title but I’ve been struggling with this for hours now.
I want the button the code is referencing to change when the button is no longer active but for some reason, even though it know the sl value has changed it doesn’t update which button it’s referencing, or at least doesn’t reference the right one. I tried putting it in a while loop and that kind of works but one click makes the sl value go up way too much, even with a wait(1) at the start.
local frame = game.Players.LocalPlayer.PlayerGui.Gui.Buying.Menu.Frame
local team = game.Players.LocalPlayer.Team
local sl = game.Players.LocalPlayer.PlayerGui.Level.Shop.Value
frame.Shop["Lvl"..tostring(sl)].MouseEnter:Connect(function()
print("Why won't you work?")
local price = frame.Shop["Lvl"..tostring(sl)].Price.Value
game.ReplicatedStorage.Buy.On:FireServer(tostring(sl),"Shop",price)
end)
frame.Shop["Lvl"..tostring(sl)].MouseLeave:Connect(function()
game.ReplicatedStorage.Buy.Off:FireServer(tostring(sl),"Shop")
end)
frame.Shop["Lvl"..tostring(sl)].MouseButton1Click:Connect(function()
local mon = game.Players.LocalPlayer.leaderstats.Money.Value
local price = frame.Shop["Lvl"..tostring(sl)].Price.Value
game.ReplicatedStorage.Buy.Click:FireServer(tostring(sl),"Shop", price)
if mon >= price then
frame.Shop["Lvl"..tostring(sl)].Visible = false
frame.Shop["Lvl"..tostring(sl)].Active = false
sl = sl + 1
frame.Shop["Lvl"..tostring(sl)].Visible = true
frame.Shop["Lvl"..tostring(sl)].Active = true
end
end)
This is only part of the code but I think it’s the relevant bit. I don’t think this is an issue server side so it’s just this local script
19:11:35.820 Why won’t you work? - Client - Buying:11
19:11:35.837 OtterCarbonara 1 Shop 0 - Server - Buy:6
That is what I get when I hover over the button the first time.
When I then click it and it moves on to the next button I get nothing in the output.
This is all of the script server side
local on = game.ReplicatedStorage.Buy.On
local off = game.ReplicatedStorage.Buy.Off
local click = game.ReplicatedStorage.Buy.Click
on.OnServerEvent:Connect(function(player,Lvl,t,price)
print(player, Lvl, t, price)
local mon = game.Players[tostring(player)].leaderstats.Money.Value
local team = game.Players:FindFirstChild(tostring(player))["Team"]
if mon < price then
game.ServerStorage.Models:FindFirstChild(tostring(team))[tostring(t)][tostring(t).."Lvl"..tostring(Lvl).."hr"].Parent = workspace[tostring(team)]
elseif mon >= price then
game.ServerStorage.Models:FindFirstChild(tostring(team))[tostring(t)][tostring(t).."Lvl"..tostring(Lvl).."h"].Parent = workspace[tostring(team)]
end
end)
off.OnServerEvent:Connect(function(player,Lvl,t)
local team = game.Players:FindFirstChild(tostring(player))["Team"]
if workspace[tostring(team)]:FindFirstChild(tostring(t).."Lvl"..tostring(Lvl).."h") ~= nil then
workspace[tostring(team)][tostring(t).."Lvl"..tostring(Lvl).."h"].Parent = game.ServerStorage.Models:FindFirstChild(tostring(team))[t]
elseif workspace[tostring(team)]:FindFirstChild(tostring(t).."Lvl"..tostring(Lvl).."hr") ~= nil then
workspace[tostring(team)][tostring(t).."Lvl"..tostring(Lvl).."hr"].Parent = game.ServerStorage.Models:FindFirstChild(tostring(team))[t]
end
end)
click.OnServerEvent:Connect(function(player,Lvl,t,price)
local team = game.Players:FindFirstChild(tostring(player))["Team"]
local mon = game.Players[tostring(player)].leaderstats.Money.Value
if mon >= price then
if (Lvl - 1) ~= 0 then
workspace[tostring(team)][tostring(t).."Lvl"..tostring(Lvl - 1)].Parent = game.ServerStorage.Models:FindFirstChild(tostring(team))[t]
end
game.ServerStorage.Models:FindFirstChild(tostring(team))[tostring(t)][tostring(t).."Lvl"..tostring(Lvl)].Parent = workspace[tostring(team)]
workspace[tostring(team)][tostring(t).."Lvl"..tostring(Lvl).."h"].Parent = game.ServerStorage.Models:FindFirstChild(tostring(team))[tostring(t)]
mon = mon - price
end
end)
When you click on the button it disappears and then the code client side should be referencing the next button in its place. Instead it does nothing. When I say no longer active I mean just like gone. Visible and Active set to false and the next button has Visible and Active set to true.
I don’t think it’s anything to do with money. I give myself like a billion. Since I don’t get the output from the local script I think it’s just because it’s being annoying.
that being said, why not change the text on the button and the matching price?
you can do that on the server, so you only need to send the remote event when it is clicked