Help me fix my shop, its not working

  1. What do you want to achieve? Keep it simple and clear!
    i wanted to create a working shop system

  2. What is the issue? Include screenshots / videos if possible!
    it doesent work with this error. i think the serverscript is the problem, becouse a massage in the localscript printed.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i have tried searching the devforum with no result

  2. Additional information

i have 2 codes, 1 being local and 1 being server.
my localscript:

local replicatedstorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local button = script.Parent
local price = script.Parent.Parent.Parent.CPrice
local chosen = script.Parent.Parent.Parent.CurrentShown
local folder = player:WaitForChild("SwordStatus")

local function onClick()
	local havecheck = folder:WaitForChild(tostring(chosen.Value)).Value
	
	if havecheck == true then
		
		replicatedstorage.Own:Fire(player)
		
	else
		local coins = player.Coins
		
		if coins.Value == price.Value or coins.Value > price.Value  then
			
			local sound = script.Parent.Bought
			sound:Play()
			replicatedstorage.BuyEvents.BoughtWCoins:FireServer(player)
			print("bought")
			
		else
			
			replicatedstorage.Broke:Fire(player)
			
		end
	end
end

button.MouseButton1Click:Connect(onClick)

my serverscript:

local price = script.Parent.Parent.Parent.CPrice
local chosen = script.Parent.Parent.Parent.CurrentShown

game.ReplicatedStorage.BuyEvents.BoughtWCoins.OnServerEvent:Connect(function(player)
	
	local folder = player:WaitForChild("SwordStatus")
	local sword = folder:WaitForChild(tostring(chosen.Value)).Value
	local coins = player.Coins
	
	coins.Value -= price.Value
	sword = true
	
end)

all help is apreciated :grin:

4 Likes

is swordstatus in your player character or the player? it will return as nil if you never mention the character if your folder is in there.

4 Likes

How do i mention the cherecter?

3 Likes

you have a player variable so you just add .Character behind it.

2 Likes

uhh that makes the localscript dont work too

4 Likes

can u take a screenshot of the contents in ur starterplayer and also when playing the game, of your player model in workspace

3 Likes

Screenshot 2024-01-14 162826

Screenshot 2024-01-14 162831

2 Likes

forgot to tell, this script is in the buy button in the gui

3 Likes

i think the most likely reason is that the player hasnt loaded yet so the folder has not appeared. the script side probably isnt the problem because the error is in the local script. is it possible if you placed the folder variable inside your function?

2 Likes

ill try wait a sec

qwertyuiopqwertyuiopqwertyuiopqwertyuip

2 Likes
replicatedstorage.BuyEvents.BoughtWCoins:FireServer(player, folder == player:WaitForChild("SwordStatus"))

did you mean this?

for your onclick() function, and you can use findfirstchild instead

1 Like

it made an error

Screenshot 2024-01-14 164046

1 Like

thats where you put the argument not the variable.

local function example()
local SwordStatus = player:FindFirstChild(“SwordStatus”)

1 Like

ooh i understand now

qwertyuiopqwertyuiop

1 Like

the localscript work, but the serverscript still isnt working

2 Likes

local sword = folder:WaitForChild(tostring(chosen.Value)).Value

you mentioned value twice

1 Like

this doesent change anything but okay

theres only one value property. mentioning it twice will return nil. i advise that you do revise on your scripting basics, i assume that you are watching a youtube how to do tutorial

1 Like

i made this script myself, and i have deleted the second .Value, and that didnt change anything.

1 Like