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.
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)