Hey there, when i touch a part that gives money, it works completely fine, but when more than 1 player touch the part tho, the duffel bag start to appear and dissapear, my friend said that my script ins’t multiplayer, how i can fix that?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DuffelBag = ReplicatedStorage:WaitForChild("Item"):FindFirstChild("DuffelBag")
local function InsertDuffelBag(Character)
DuffelBag:Clone()
DuffelBag.Parent = Character
end
workspace.Banks["2bcd60e8-8f76-44c9-811b-31f0efd1f142"].Layout.Money.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local Character = player.Character or player.CharacterAdded:Wait()
InsertDuffelBag(Character)
end
end)
Note: I Can’t show any examples of video, because my pc is so much laggy and none of my friends are disponible.
You are creating a clone but parenting the original.
Instead what you want to do is store the clone in a new variable and then parent using that variable, like so:
local function InserDuffelBag(Character)
local clonedBag = DuffelBag:Clone()
clonedBag.Parent = Character
end
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Items = RS:WaitForChild("Item")
local Bag = Items:WaitForChild("DuffelBag")
local function InsertDuffelBag(Character)
local BagClone = Bag:Clone()
Bag.Parent = Character
end
workspace.Banks:FindFirstChild("2bcd60e8-8f76-44c9-811b-31f0efd1f142").Layout.Money.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = Players:GetPlayerFromCharacter(hit.Parent)
local Character = player.Character
InsertDuffelBag(Character)
end
end)