Fireserver won’t work for some reason, i tried changing the directory, changing names moving things, etc. But it still wouldn’t work.
od would print but od2 wouldn’t
This is the local script
local dollar10 = script.Parent.a10
local dollar20 = script.Parent.a20
local dollar50 = script.Parent.a50
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local connection = script.Parent.Parent.connection.Value
dollar10.MouseButton1Click:Connect(function(k, info)
print("od")
RemoteEvent:FireServer("10")
end)
dollar20.MouseButton1Click:Connect(function(k, info)
print("od")
RemoteEvent:FireServer("20")
end)
dollar50.MouseButton1Click:Connect(function(k, info)
print("od")
RemoteEvent:FireServer("50")
end)
and this is the server script
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local connection = script.Parent.Parent.connection.Value
RemoteEvent.OnServerEvent:Connect(function(k, info)
if info == "10" then
connection.Balance.Value = connection.Balance.Value + 10
elseif info == "20" then
connection.Balance.Value = connection.Balance.Value + 20
elseif info == "50" then
connection.Balance.Value = connection.Balance.Value + 50
end
end)
You should move the ServerScript someplace else. Placing scripts inside UI is bad practice. Same goes for RemoteEvents. Place them in ReplicatedStorage.
Try using WaitForChild for a10, a20 and a50 in the first 3 lines of code. Also what is this supposed to be? connection.Balance.Value
I see you have connection there, but it doesn’t have any children so it should be connection.Value.
And finally, when you put an IntValue, or any Value object for that matter in a variable, refer to the object itself, not its value so instead of
local connection = script.Parent.Parent.connection.Value
it should be
local connection = script.Parent.Parent.connection
and then if you need to change it’s value you can do connection.Value
local connection = script.Parent.Parent.connection.Value simply puts the value of the connection into the variable, and if you change the variable, the original object will not be changed.
First, you do not have to do :WaitForChild() if it shares a parent with the script
Second, try doing a print on RemoteEvent.OnServerEvent
Example:
RemoteEvent.OnServerEvent:Connect(function(k, info)
print'Fired'
if info == "10" then
connection.Balance.Value = connection.Balance.Value + 10
elseif info == "20" then
connection.Balance.Value = connection.Balance.Value + 20
elseif info == "50" then
connection.Balance.Value = connection.Balance.Value + 50
end
end)
local MainFrame = script.Parent
local Dollar1 = MainFrame.a10
local Dollar2 = MainFrame.a20
local Dollar5 = MainFrame.a50
local Remote = MainFrame:WaitForChild("RemoteEvent")
Dollar1.MouseButton1Click:Connect(function()
Remote:FireServer("10")
end)
Dollar2.MouseButton1Click:Connect(function()
Remote:FireServer("20")
end)
Dollar5.MouseButton1Click:Connect(function()
Remote:FireServer("50")
end)
ServerScript
local MainFrame = script.Parent
local Balance = MainFrame.Parent.Parent.Parent.Balance
local Remote = MainFrame.RemoteEvent
Remote.OnServerEvent:Connect(Player, Arg)
if Arg == "10" then
Balance.Value += 10
elseif Arg == "20" then
Balance.Value += 20
elseif Arg == "50" then
Balance.Value += 50
end
end)