Confusing bug with "FindFirstChild"!

Hey there! I’m making a PVP Game, but it has seem that i have ran into a bug.
Heres the code:

local plr = script.Parent.Parent.Parent.Parent.Parent.Parent or script.Parent.Parent.Parent.Parent.Parent.Parent.CharacterAdded:Wait()
local cost = script.Parent.Configuration.Cost

local name = script.Parent.Parent.AbilityName
local ps = plr:FindFirstChild("PrivateStats")

script.Parent.MouseButton1Click:connect(function()
	local namee = script.Parent.Configuration.naame
	namee.Value = name.Text
	if ps:FindFirstChild(namee.Value).Value == true then -- BUG
		print("already bought")
	else
		if plr.leaderstats.Souls.Value >= cost.Value then
			plr.leaderstats.Souls.Value -= cost.Value
			plr:FindFirstChild("PrivateStats"):FindFirstChild(name.Text).Value = true
			print("Bought")
		end
	end
end)

What it’s suppose to do
It’s suppose to get the stringvalue’s value to find it on the player’s list. It’s not working though.

Bug:

Thanks for reading.

the problem is you aren’t getting the player properly so ps would be nil

local Player = game.Players.LocalPlayer
local PrivateStats = Player:WaitForChild("PrivateStats")

This isn’t a local script, though?

it should be a localscript
i can see you’re using buttons

If its a localscript, then it would break the entire system and it’s not trying to be complicated.

I have fixed it with remote events

i was just about to say this:

because you probably aren’t using RemoteEvents

you should have a RemoteEvent that lets you buy stuff
you could even save what the player bought and it doesn’t have to be complicated

-- LocalScript to buy an item
local RS = game:GetService("ReplicatedStorage")
local ShopEvent = RS.ShopEvent -- RemoteEvent in ReplicatedStorage
script.Parent.MouseButton1Click:connect(function()
  ShopEvent:FireServer(--[[Send the item name]])
end)
-- ServerScript to check if players can buy items
local RS = game:GetService("ReplicatedStorage")
local ShopEvent = RS.ShopEvent

ShopEvent.OnServerEvent:Connect(function(Player, TargetItem)
  -- Check if player has enough souls to buy TargetItem and update their PrivateStats and Shop
end)

I already used remotes! But thanks for trying to help. (edit: Yes, it does save.)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.