My GUI is in StarterGui, the MouseButton1Down event is recieved from a LocalScript and passed to the server, and all the elements of the GUI have Active enabled. I have no idea what’s not working.
Unfortunately I don’t know why your scripts aren’t running.
It may be something to do with the screengui, as I have tried placing individual scripts inside the buttons that fire when the button is clicked, but nothing happens.
local Collect = script.Parent.Collect
local Buy = script.Parent.Buy
Collect.MouseButton1Click:Connect(function()
print("hi")
script.Parent.RemoteEvent:FireServer("collect")
end)
Buy.MouseButton1Click:Connect(function()
print("hi")
script.Parent.RemoteEvent:FireServer("buy")
end)
server script code
local GUI = script.Parent
local Bar = GUI.Bar
local Fill = Bar.Fill
local Buy = GUI.Buy
local Collect = GUI.Collect
local Player
repeat
task.wait(1)
Player = GUI.Parent.Parent
until Player.ClassName == "Player"
local CashBank = 0
local Rungs = {}
local Tween_Info = {
TweenInfo = TweenInfo.new(0.75, Enum.EasingStyle.Linear);
Goal = {Size = UDim2.new(1,0,1,0)};
}
local Tween = game:GetService("TweenService"):Create(Fill, Tween_Info.TweenInfo, Tween_Info.Goal);
local Screen = GUI.Adornee
local Map = Screen.Parent.Parent
local RungModel = game.ServerStorage.GameData["Tycoon Battle"].Rung
local Origin = Map.RungOrigin.Position
local RungOffset = 3 -- size of the rungs
local function CreateNewRung()
local Number = #Rungs + 1
local Postion = Vector3.new(Origin.X, (Origin.Y-RungOffset)*(Number*RungOffset), Origin.Z)
local Rung = RungModel:Clone()
Rung:PivotTo(CFrame.new(Postion))
Rung.Parent = Map
table.insert(Rungs, Rung)
end
script.Parent.RemoteEvent.OnServerEvent:Connect(function(_, t)
if t=="collect" then
local Cash = tonumber(string.sub(Collect.Text, 9, -6))
print(Cash, string.sub(Collect.Text, 9, -6))
if Cash then
CashBank = 0
Collect.Text = "Collect "..tostring(CashBank).." Cash"
Player.leaderstats.Cash.Value += 1
else
print(Player,"cash is nil")
end
elseif t=="buy" then
local PlayerCash = Player.leaderstats.Cash.Value
if PlayerCash >= 10 then
Player.leaderstats.Cash.Value -= 10
CreateNewRung()
end
end
end)
task.defer(function()
while true do
Tween:Play()
Tween.Completed:Wait()
Fill.Size = UDim2.new(0,0,1,0)
CashBank += 1
Collect.Text = "Collect "..tostring(CashBank).." Cash"
end
end)
For some reason, my solution is setting the AlwaysOnTop value of the screen gui to true. I have not changed anything except this. I wonder why this is the behavior.