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

Shop System working oddly?

Asked by 5 years ago
Edited 5 years ago

Alright, so I've been asking a lot of things as of recently, but this is the last thing I'm wondering. (I'm fairly new to scripting ;v;)

I have stats in my game, in the ServerScriptService. One is for the ingame points, the second is for a buyable item, and third is another buyable item.

When you buy an item, two local scripts within a textbutton call for a RemoteEvent, and check if the player has enough points to buy the item. If they do, it subtracts those points from the player, and changes the item's value to 2. If the player leaves and comes back, the game checks if the item's value is 2. If its 2, it means they bought the item already, and it won't ask them to buy the item anymore, since they own it now.

I made a second item in the game you can buy, that works identical to the above item, but with different names. (The first item is called "item," the second is called "itemtwo.")

But for some reason, if you buy the second item, its value changes to 2, but resets back to 0 when you leave and come back. The two buttons are identical other than names. Does anyone know why this is happening?

If it helps, both acess the same DataStoreService. I also have two different RemoteEvents called "RemoteEvent1" and "RemoteEvent2." Item 1 uses the first one, and item 2 uses the second. I didn't know if this was neccesary, but I did it just incase.

What could I be doing wrong? I checked carefully, and both buttons work the exact same, so why does Button 2 reset its value to 0 when someone leaves and comes back, rather than staying at 2? I'm very new to scripting, so I probably sound like a huge dummy, but just hoping someone knows what I could've done wrong so I can fix it!!

Here are the scripts that Item1 uses. (please note that 'pawprints' is the type of ingame points in the game- its a pet simulator game.)

First script (located in a textbutton- its a local script)

script.parent.MouseButton1Down:Connect(function()

        game.ReplicatedStorage.RemoteEvent1:FireServer(150)

end)

script.Parent.MouseButton1Down:connect(function()

   local player = game.Players.LocalPlayer

    if player.Stats.Pawprints.Value >= 150 then
    script.parent.Active = false
    script.parent.Visible = false
end

end)

Second script (located in the same textbutton, also a local script)

 local player = game.Players.LocalPlayer

    if player.Item.Itemnumber.Value == 2 then
    script.parent.Active = false
    script.parent.Visible = false

end

Third script (located in the starterpack. I didn't know where else to put it- its a server script)

game.ReplicatedStorage.RemoteEvent1.OnServerEvent:Connect(function(player, value)

        if player.Stats.Pawprints.Value >= 150 then

               player.Stats.Pawprints.Value = player.Stats.Pawprints.Value- 150
                player.Item.Itemnumber.Value = 2

        end

end)

Item Two's scripts look just like this, except any instance of "item/itemnumber" are replaced with "item2/itemnumber2," and "RemoveEvent1" is changed to "RemoteEvent2."

0
Where is your script?? User#19524 175 — 5y
0
Oh oops- I forgot to post it. One sec, I'll edit it to include the scripts. yoshikins101 11 — 5y
0
Your server script shouldn’t be in StarterPack. It should be in ServerScriptService. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Heres the problem with your last script:

You put it in the Backpack, when the only places that Scripts run are under Workspace or ServerScriptService.

To fix this, put your script under one of those two. It doesn’t work because it didn’t run.

0
Ah, it works now! Thank you!! yoshikins101 11 — 5y
Ad

Answer this question