GUI Button don't work

Hello Guys,
I need help with my Script because it dont work i don’t know what to do.
There is no error in the Output and no warning.
I try to make if you press a button your Clicks get selled and you get Coins for the Clicks.

Here is the Script i use for this:

local Part = script.Parent
local player = game.Players.LocalPlayer

Part.MouseButton1Click:Connect(function()
		local leaderstats = player:WaitForChild("leaderstats")
		local Currency = leaderstats:WaitForChild("Coins") -- put the money of the leaderstats
		local Selling = leaderstats:WaitForChild("Clicks") -- put what you selling 
		if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value *3
			Selling.Value = 0
		end
	end
end)

And here is a Video for Example:

Pls somebody help me :slight_smile:

3 Likes

Is this a server script or localscript?
Something like this should be handled on the server, and server scripts cannot get a LocalPlayer.
Also, what is Part? A UI object or what? MouseButton1Click does not return anything so therefore “click” would be useless, that’s why it may not working

1 Like

Its a Local Script.

“Part” is just the name of the Button

Ah ok, remove “click” and the “if” statement for click then try again
What’s the purpose for the click argument anyway?

I already tried it in the Video, i posted the wrong script i change it now

This is the script is used in the Video

I think this has to be done with remote events

i dont see anything wrong to why this would happen

You should “sell” your clicks on the server side by firing some kind of sell remote. To do this put a server script in ServerScriptService and have a RemoteEvent in ReplicatedStorage.

RemoteEvent.OnServerEvent:connect(function(Player)
– run your code here
end)

But FireClient does not work in a Gui Button

still even on the client i don’t understand why his “clicks” are not resetting and instead carrying on until the click button is next pressed

It’s FireServer() on the client

What do you mean? It’s meant ot be FireServer

You cant use fireClient on Local Scripts, thats supposed to e used in ServerScripts. Learn more here:

Local Script:

RemoteEvent:FireServer()

Server Script: (Place this ins ServerScriptService

RemoteEvent.OnServerEvent:Connect(function(player)
   --code stuff
end)

Local Script:

Part.MouseButton1Click:Connect(function()
   remoteevent:FireServer()
end)

ServerScript:

remoteevent:OnServerEvent:Connect(function()
    local leaderstats = player:WaitForChild("leaderstats")
		local Currency = leaderstats:WaitForChild("Coins") -- put the money of the leaderstats
		local Selling = leaderstats:WaitForChild("Clicks") -- put what you selling 
          	if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value *3
			Selling.Value = 0
		end
end)

The error in this case is in the last line of the script, as it has an extra bracket. The correction would be:

local Part = script.Parent
local player = game.Players.LocalPlayer

Part.MouseButton1Click:Connect(function()
		local leaderstats = player:WaitForChild("leaderstats")
		local Currency = leaderstats:WaitForChild("Coins") -- put the money of the leaderstats
		local Selling = leaderstats:WaitForChild("Clicks") -- put what you selling 
		if Selling.Value > 0 then
			Currency.Value = Currency.Value + Selling.Value *3
			Selling.Value = 0
		end
	end)

Removed extra bracket after end function.

I tried it but i can’t use remoteevent:OnServerEvent:Connect(function() in a normal Script in ServerScript Service.

This is how i maked it:

local RemoteEvent = game.ReplicatedStorage.SellToken
local remoteevent = game:ReplicatedStorage.SellToken

RemoteEvent.OnServerEvent:Connect(function(player)
remoteevent:OnServerEvent:Connect(function()
    local leaderstats = player:WaitForChild("leaderstats")
		local Currency = leaderstats:WaitForChild("Coins")
		local Selling = leaderstats:WaitForChild("Clicks")
			Currency.Value = Currency.Value + Selling.Value *3
			Selling.Value = 0
		end
end)
end)

And this is the LocalScript in the Button:

Part.MouseButton1Click:Connect(function()
   remoteevent:FireServer()
end)
1 Like

Ah let me just change that, you put to remoteevents inside of each other:


local remoteevent = game:GetService("ReplicatedStorage").SellToken

remoteevent:OnServerEvent:Connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
		local Currency = leaderstats:WaitForChild("Coins")
		local Selling = leaderstats:WaitForChild("Clicks")
			Currency.Value = Currency.Value + Selling.Value *3
			Selling.Value = 0
		end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.