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)
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
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)
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)