Hello developers! I have a problem with my shopping system; it works fine whenever there’s only one person in the server. Whenever there’s more than one, and you go to shop, the script gives you an item for every person in the server instead of just one. For example, if there’s 3 people in the server, the system gives you 3 items.
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local shop = workspace.JerryIsland.JerrysShop
local shopRemote = ReplicatedStorage:WaitForChild("JerryRemote")
local player = Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid
for i, v in ipairs(shop:GetDescendants()) do
if v:IsA("ProximityPrompt") then
if v.Name == "KnifePrompt" then
v.PromptButtonHoldEnded:Connect(function()
shopRemote:FireServer(v.Name)
end)
end
if v.Name == "SSPrompt" then
v.PromptButtonHoldEnded:Connect(function()
shopRemote:FireServer(v.Name)
end)
end
if v.Name == "ShieldPrompt" then
v.PromptButtonHoldEnded:Connect(function()
shopRemote:FireServer(v.Name, character)
end)
end
end
end
Server Script:
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local WeldMod = require(ServerScriptService.ShieldWeld)
local shopRemote = ReplicatedStorage:WaitForChild("JerryRemote")
local shopItems = ServerStorage:FindFirstChild("ShopItems")
shopRemote.OnServerEvent:Connect(function(player, promptName, character)
local backpack = player:FindFirstChildOfClass("Backpack")
local cost = 0
if promptName == "KnifePrompt" then
cost = 7
if player.leaderstats.Marks.Value >= cost then
local knifeClone = shopItems.Knife:Clone()
knifeClone.Parent = backpack
player.leaderstats.Marks.Value -= cost
else
return
end
end
if promptName == "SSPrompt" then
cost = 13
if player.leaderstats.Marks.Value >= cost then
local swordClone = shopItems.ShortSword:Clone()
swordClone.Parent = backpack
player.leaderstats.Marks.Value -= cost
else
return
end
end
if promptName == "ShieldPrompt" then
cost = 6
if player.leaderstats.Marks.Value >= cost then
local originalShield = shopItems:FindFirstChild("Shield")
local shield = originalShield:Clone()
local attachPoint = shield:FindFirstChild("Attach")
shield.Parent = workspace
WeldMod.Weld(shield, attachPoint, character)
player.leaderstats.Marks.Value -= cost
else
return
end
end
end)
What can I do to solve my dilemma?