So basically what I want to do is to make a script that will duplicate a part all around my map. But the problem is that the part duplicates but the script inside the part doesn't work.
Edit1: Main Script is located in workspace
Main Script to duplicate parts
while wait(0.1) do
local bullet = game.Workspace.Bullet:Clone()
local jump = game.Workspace.Jump:Clone()
local invisible = game.Workspace.Invisible:Clone()
local health = game.Workspace.Medkit:Clone()
local speed = game.Workspace.Speed:Clone()
bullet.Parent = workspace
bullet.Position = Vector3.new(math.random(-205, 186), 20, math.random(-132, 262))
end
Script inside the part named bullet
Edit1: The script is located in a part that is in workspace
local part = script.Parent
local DoubbleeBulletGamepass = true
game.Players.PlayerAdded:Connect(function(player)
local maxBullet = player:WaitForChild("leaderstats"):WaitForChild("MaxBullet")
local bulletLeft = player:WaitForChild("leaderstats"):WaitForChild("BulletLeft")
local hitName = nil
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hitName = hit.Parent.Name
if bulletLeft.Value < maxBullet.Value then
if DoubbleeBulletGamepass == true and bulletLeft.Value <= 4 then
bulletLeft.Value = bulletLeft.Value + 2
elseif DoubbleeBulletGamepass == true and bulletLeft.Value < maxBullet.Value then
bulletLeft.Value = bulletLeft.Value + 1
elseif DoubbleeBulletGamepass == false and bulletLeft.Value < maxBullet.Value then
bulletLeft.Value = bulletLeft.Value + 1
end
part:Destroy()
elseif bulletLeft.Value >= maxBullet.Value then
print("you have max ammo")
end
end
end)
end)
I have tried to put the main script variables to be from replicated storage but it still doesn't work(Also if you can could you please explain what you did)

2 comments
https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter
thank you for the explanation