Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Shop script wont work, do i need remotes?! There is no error in output

I've made a script and put this code but it wont work what is the error?

local price = 2400

local price = 2400

script.Parent.MouseButton1Click:connect(function(click)
	local player = game.Players:WaitForChild(click.Name)
	if player.leaderstats:FindFirstChild("Coins").Value >= price.Value then
local char = player.Character
char.UpperTorso.Position = Vector3.new(85.64, 10.728, 16.66)
	local coins =	player.leaderstats:FindFirstChild("Coins")
	coins.Value = coins.Value - 2400
		
	end
end)

please help me :( there is no error in output! Im kinda new to scripting

1 comment

0

a value created by the server cant be changed by a local script(the client). you'll need a remote event on line 9.

1 answer

✓ Accepted answer

You would need to use a remote event and local script. Your script is editing the value from the clients side, so anything changed from the server side would reset the change. So put a remote event in replicated storage. Here is the local script:

local price = 2400

script.Parent.MouseButton1Click:connect(function(click)
    local player = game.Players.LocalPlayer
    if player.leaderstats:FindFirstChild("Coins").Value >= price.Value then
game.ReplicatedStorage.RemoteEvent:FireServer()

    end
end)

This server script goes in server script service:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)
local char = plr.Character
char.UpperTorso.Position = Vector3.new(85.64, 10.728, 16.66)
    local coins =   plr.leaderstats:FindFirstChild("Coins")
    coins.Value = coins.Value - 2400
end)

3 comments

0

:connect is deprecated use :Connect

0

also line 2 and 4 of the server script is wrong, you used player.Character instead of plr.Character

0

still does not work...

This discussion is preserved as it was. New answers, comments, and votes are closed.