Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

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. DinozCreates 1070 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
:connect is deprecated use :Connect yHasteeD 1819 — 5y
0
also line 2 and 4 of the server script is wrong, you used player.Character instead of plr.Character DinozCreates 1070 — 5y
0
still does not work... mdbaten2 24 — 5y
Ad

Answer this question