I am spawning in parts from a LocalScript because I only want the individual player to be able to see those parts. I would like to put this in a module script so it can’t get exploited. I am trying to delete those parts as a part of a part reset. Thanks for any help
Here is all the code for the part spawer (local script):
local plr = game:GetService("Players").LocalPlayer
local workspace = game:GetService("Workspace")
local rs = game:GetService("ReplicatedStorage")
local remoteFolder = rs:WaitForChild("Remotes")
local isStart = plr:WaitForChild("Data"):WaitForChild("isStart")
local isStopped = plr:WaitForChild("Data"):WaitForChild("isStopped")
function decreasePartTransparency(part)
local targetTransparency = 0.9
local transparencyTick = 0.01
local duration = (0.9 - part.Transparency) / transparencyTick
local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local transparencyTween = game:GetService("TweenService"):Create(part, tweenInfo, { Transparency = targetTransparency })
transparencyTween:Play()
end
local partsFolder = Instance.new("Folder")
partsFolder.Parent = workspace
partsFolder.Name = "PartsFolder"
isStart.Changed:Connect(function()
while task.wait() and isStart.Value == true and isStopped.Value == false do
print("isStart")
local part = Instance.new("Part")
part.CastShadow = false
part.BrickColor = BrickColor.new(Color3.new(0.00784314, 0.270588, 1))
part.Transparency = 0.6
part.Position = Vector3.new(math.random(-100, 100), math.random(110, 150), math.random(-100, 100))
part.Parent = partsFolder
remoteFolder:WaitForChild("AddPart"):FireServer(plr)
decreasePartTransparency(part)
end
end)
isStopped.Changed:Connect(function()
while task.wait() and isStart.Value == true and isStopped.Value == false do
print("isStopped")
local part = Instance.new("Part")
part.CastShadow = false
part.BrickColor = BrickColor.new(Color3.new(0.00784314, 0.270588, 1))
part.Transparency = 0.6
part.Position = Vector3.new(math.random(-100, 100), math.random(110, 150), math.random(-100, 100))
part.Parent = partsFolder
remoteFolder:WaitForChild("AddPart"):FireServer(plr)
decreasePartTransparency(part)
end
end)
And here is all the code for the server-side OnRemoteEvent:
remoteFolder:WaitForChild("AddPart").OnServerEvent:Connect(function(player)
player:WaitForChild("leaderstats"):WaitForChild("Parts").Value += 1
end)
remoteFolder:WaitForChild("StartParts").OnServerEvent:Connect(function(player)
player:WaitForChild("Data"):WaitForChild("isStart").Value = true
end)
remoteFolder:WaitForChild("StopParts").OnServerEvent:Connect(function(player)
player:WaitForChild("Data"):WaitForChild("isStart").Value = false
end)
remoteFolder:WaitForChild("ResetParts").OnServerEvent:Connect(function(player)
print("ResetReq")
player:WaitForChild("Data"):WaitForChild("isStopped").Value = true
resetPartsModule.deleteParts()
print("ResetFin")
player:WaitForChild("Data"):WaitForChild("isStopped").Value = false
**strong text**
player:WaitForChild("Data"):WaitForChild("PartsValue").Value = 0
end)
I get the print 'ResetReq'
but not 'ResetFin'
And here is the code for the module script
local module = {}
function module.deleteParts()
local plr = game:GetService("Players").LocalPlayer
for _, part in ipairs(game:GetService("Workspace"):WaitForChild("PartsFolder"):GetChildren()) do
part:Destroy()
end
end
return module