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

Why will this sell script not work?

Asked by 2 years ago
Edited 2 years ago

I have been making a Roblox simulator and the sell has not been working. I have tried multiple scripts and people say they work but none of them have been working for me. There are no errors but the cash never changes. Here they are.

It has a remote event in ReplicatedStorage and a server script in a part. I have this in a different game and it is still working so I don't know what happened in the current one. Here is the script from the part. Now, this script is taken from the game its working in because I took it out of the one I'm making.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        game.ReplicatedStorage.Sell:Fire(player)
    end
end)

This is the script in a server script in server script service.


ReplicatedStorage.Sell.Event:Connect(function(player) if player ~= nil then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.Sticks.Value*2 player.leaderstats.Sticks.Value = 0 end end)
0
If you're saying that the script is taken from another game and it works for that game then it's either: a) something is placed incorrectly in the KingDomas 153 — 2y
0
explorer or b) the directory for where the script is looking (example game.Workspace) is incorrect. KingDomas 153 — 2y

2 answers

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

Hello, you mistakened bindable event calls for remote event ones :D!

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)

        game.ReplicatedStorage.Sell:FireServer()
    end
end)

And thats server one:

ReplicatedStorage.Sell.OnServerEvent:Connect(function(player)
    if player ~= nil then
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + player.leaderstats.Sticks.Value*2
        player.leaderstats.Sticks.Value = 0
    end
end)

Ad
Log in to vote
0
Answered by 2 years ago

This problem has been solved from Stack Overflow. If you want to see how it was solved just read through the stuff here. https://stackoverflow.com/questions/72065230/how-do-i-make-a-sell-script-roblox/72070998#72070998

Answer this question