My upgrade script isnt working

im making a game where you can upgrade a multiplier with points and the script I have doesn’t work
the issue is that when i press the button nothing happens
ive looked throughout youtube and the dev forum and nothing solves my problem


local plr = game.Players.LocalPlayer
local button = script.Parent

local pricetext = script.Parent.Parent.price

--stats--

local statfolder = plr:WaitForChild("statfolder")
local ufolder = plr:WaitForChild("ufolder")
local points = statfolder:WaitForChild("points")
local spawncap = statfolder:WaitForChild("spawncap")
local scprice = ufolder:WaitForChild("scprice")

game.Players.PlayerAdded:Connect(function()
	pricetext.Text = scprice.Value
end)
scprice:GetPropertyChangedSignal("Value"):Connect(function()
	pricetext.Text = scprice.Value
end)

button.Activated:Connect(function()
	if points.Value >= scprice.Value then
		points.Value -= scprice.Value
		scprice.Value = scprice.Value * 1.15
		spawncap.Value += 5
		wait(0.5)
	end
end)

pls help

1 Like

this is the part that im refering to when i say the button doesnt work

If variable button is a GUI button (TextButton / ImageButton), you could try using button.MouseButton1Down:Connect() instead of button.Activated:Connect(). Otherwise, what is the class of button?

its a gui button and even after i changed it to mousebutton1click it still doesnt work

If you change the points on the local side it doesn’t replicate to server side.

oh yea i forgot how scripts work

1 Like

Hello, the essence of your idea is not fully understood, but you can try to do it using button.MouseButton1Down:Connect(), and for a complete check at the end after wait(0.5) add print(“test”).
If there is no message in Output, then most likely something is done wrong, and it is better to tell in more detail about this problem.

As for the change in the local script, you can change the values and it will be detected as a change, it all depends on what you need to do.

do i have the put the player in the parenthesis if its an onserverevent function

I don’t fully understand what you want to do. If you just want to make enhancements with points, then the script seems to be correct except for button.Activated, in which case it’s better to use button.MouseButton1Down:Connect().
And in general terms, if you do not consider that this is a local script, then perhaps the fact is that there are not enough points?

Correct. Whenever receiving a Remote on the Server, there’ll be the person who Fired the Remote passed as the first Parameter or Argument.

Secondly, you shouldn’t handle PlayerAdded on LocalScripts/the client the way it currently is. I highly recommend looking into Remotes, as they’ll be your best friend here. Handling playerdata/subtracting values on the client is bad practice.

Player Class
Leaderboards
Remote Events & Functions

PlayerAdded can be used in a local script, it all depends on the script functions.
In this case, I agree, it is not necessary.
And about remote events, this is an important part.

That hasn’t been a thing until recently, still horrid practice with no practional use in OP’s case.

Yes, it is difficult to use, but the very fact of using it is possible.

For what OP is requesting, they don’t want to handle anything on the client judging on the way it’s generally structured. There’s no point of it in this case, is my point.

Friend, don’t worry, keep it up, it seems to work.
Devrb

Local

local plr = game.Players.LocalPlayer
local button = script.Parent

local pricetext = script.Parent.Parent.price

--Event--
local Event = script.RemoteEvent
	--stats--

local statfolder = plr:WaitForChild("statfolder")
local ufolder = plr:WaitForChild("ufolder")
local points = statfolder:WaitForChild("points")
local spawncap = statfolder:WaitForChild("spawncap")
local scprice = ufolder:WaitForChild("scprice")

scprice.Changed:Connect(function()
	pricetext.Text = scprice.Value
end)

button.MouseButton1Click:Connect(function()
	if points.Value >= scprice.Value then
		Event:FireServer()
	end
end)

Server

script.Parent.OnServerEvent:Connect(function(Plr)
	local points = Plr:FindFirstChild("statfolder"):FindFirstChild("points")
	local spawncap = Plr:FindFirstChild("statfolder"):FindFirstChild("spawncap")
	local scprice = Plr:FindFirstChild("ufolder"):FindFirstChild("scprice")
	if points.Value >= scprice.Value then
		points.Value -= scprice.Value
		scprice.Value = scprice.Value * 1.15
		spawncap.Value += 5
	end
end)

But this is so, for example, you will still need to learn in the future.

so i changed the script to be like this with some changes and it didnt work, then i removed the changes and just put the script you wrote exactly and it didnt work

i also replaced this part with another script saying this

game.Players.PlayerAdded:Connect(function(plr)
	local ufolder = plr:WaitForChild("ufolder")
	scprice = ufolder:FindFirstChild("scprice")

	script.Parent.Text = scprice.Value	
end)

Wait()
scprice:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = scprice.Value
end)

And, I forgot to say one more thing, if you want the text to appear when the player enters the game, then you don’t need to use PlayerAdded for this, just write it into the script and that’s it, it will play and will work, just after the player respawns, the text disappears, but it’s better to just use

script.Parent.Text = scprice.Value

And about GetPropertyChangedSignal, everything is easier, in Value there is almost never anything that changes except for the value.
And about the fact that it does not work, it is rather strange, since by and large the script should have worked.
In general terms, please tell me what’s wrong with your Output, or try adding prints to some parts of the script to determine where it stops working, or something is not done right.

I’m writing this text through a translator, so if it’s a little unclear about PlayerAdded, then in short I’ll say, if you want the number of points in the player to be in the TextLable, then just use

script.Parent.Text = scprice.Value

Instead of

game.Players.PlayerAdded:Connect(function(plr)
	local ufolder = plr:WaitForChild("ufolder")
	scprice = ufolder:FindFirstChild("scprice")

	script.Parent.Text = scprice.Value	
end)

Since PlayerAdded is only executed when a player connects to the server, and after the first respawn in the player, the number of points will be missing.
When using the script without PlayerAdded, this action will be executed every time a person enters the game or respawns.
And the text is reset after each respawn.