#Local Part Spawn Collection System
1 messages · Page 1 of 1 (latest)
This is the script the error is coming from, Its a normal script inside ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local CollectEvent = ReplicatedStorage.Events.CollectibleEvents.Collect
local GetSpawnPartEvent = ReplicatedStorage.Events.CollectibleEvents.GetSpawnPart
local RngClient = require(ServerScriptService.RngClient)
local SpawningPart = Workspace.SpawningPart
GetSpawnPartEvent.OnServerInvoke = function(player)
print("Server Invoked for SpawnPartEvent")
local Rng = RngClient.SelectRandom(player)
local Color = Rng[3]
local Value = Rng[4]
local RandomPos = SpawningPart.Position + Vector3.new(math.random(-SpawningPart.Size.X/2, SpawningPart.Size.X/2),SpawningPart.Size.Y/2 + 1,math.random(-SpawningPart.Size.Z/2, SpawningPart.Size.Z/2))
return {Color = Color,Value = Value,Position = RandomPos}
end
CollectEvent.OnServerEvent:Connect(function(player, part)
print("Collect Event Recieved")
if not part then warn("Error-1") return end
if not part:IsDescendantOf(workspace.collectiblesFolder) then warn("Error0") return end
local char = player.Character
if not char then warn("Error1") return end
local hrp = char:FindFirstChild("HumanoidRootPart")
if not hrp then warn("Error2") return end
local radius = player:GetAttribute("Radius") or 0
if (part.Position - hrp.Position).Magnitude <= radius then
local reward = part:GetAttribute("Value") or 1
print(player.Name .. " collected a part worth " .. reward)
local state = player:GetAttribute("Money")
player:SetAttribute("Money", state + reward)
part:Destroy()
else
warn("Error3")
end
end)```
This is the script which creates the part located in StarterCharacterScripts and is a local script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local GetSpawnPartEvent = ReplicatedStorage.Events.CollectibleEvents.GetSpawnPart
local Player = Players.LocalPlayer
local CollectiblesFolder = Workspace:WaitForChild("collectiblesFolder")
local SpawnSpeed = nil
Player:GetAttributeChangedSignal("SpawnSpeed"):Connect(function()
SpawnSpeed = Player:GetAttribute("SpawnSpeed")
print("SpawnSpeed updated:", SpawnSpeed)
end)
local function SpawnCollectible()
local Data = GetSpawnPartEvent:InvokeServer(Player)
if Data then
local Color = Data.Color
local Value = Data.Value
local Pos = Data.Position
local part = Instance.new("Part")
part.Size = Vector3.new(1,2,1)
part.Anchored = true
part.CanCollide = false
part.Color = Color
part:SetAttribute("Value", Value)
part.Name = "Collectible"
part.Parent = CollectiblesFolder
part.Position = Pos
else
warn("No data was given")
end
end
task.spawn(function()
while true do
SpawnCollectible()
task.wait(SpawnSpeed)
end
end)```
not sure, but maybe is cuz part:IsDescendantOf(Workspace.collectiblesFolder) "part" doesnt exist, if "part" is this (code that u have in your local):
local part = Instance.new("Part")
part.Size = Vector3.new(1,2,1)
part.Anchored = true
part.CanCollide = false
part.Color = Color
part:SetAttribute("Value", Value)
part.Name = "Collectible"
part.Parent = CollectiblesFolder
part.Position = Pos
cuz u are creating that from the local script, so when the server try to find it, it simple doesnt found it
yeah i understand that but im not really sure how to fix it
** You are now Level 16! **
create the part from the server side
okay can you help me
so i made some new code
local GetSpawnPart = ReplicatedStorage.Events.CollectibleEvents:WaitForChild("GetSpawnPart")
local SpawningPart = Workspace.SpawningPart
local function GetRandomData(player : Player)
local Rng = RngClient.SelectRandom(player)
local Color = Rng[3]
local Value = Rng[4]
local RandomPos = SpawningPart.Position + Vector3.new(math.random(-SpawningPart.Size.X/2, SpawningPart.Size.X/2),SpawningPart.Size.Y/2 + 1,math.random(-SpawningPart.Size.Z/2, SpawningPart.Size.Z/2))
return {Color = Color,Value = Value,Position = RandomPos}
end
local function CreatePart(Data, Folder)
if Data then
local Color = Data.Color
local Value = Data.Value
local Pos = Data.Position
local part = Instance.new("Part")
part.Size = Vector3.new(1,2,1)
part.Anchored = true
part.CanCollide = false
part.Color = Color
part:SetAttribute("Value", Value)
part.Name = "Collectible"
part.Parent = Folder
part.Position = Pos
part.Transparency = 1
part.CanCollide = false
return part
else
warn("No data was given")
end
end
local function SpawnSet(player : Player)
local SpawnTime = player:GetAttribute("SpawnSpeed")
local CollectiblesFolder = Workspace:WaitForChild("Collectables_" .. player.Name)
local Data = GetRandomData(player)
local Part = CreatePart(Data, CollectiblesFolder)
if Part then
GetSpawnPart:InvokeClient(player, Part)
else
warn("Varible Part is nil")
end
task.wait(SpawnTime)
SpawnSet(player)
end
Players.PlayerAdded:Connect(function(player)
local PlayerFolder = Instance.new("Folder")
PlayerFolder.Name = "Collectables_" .. player.Name
PlayerFolder.Parent = Workspace
SpawnSet(player)
end)```
This is what spawns the parts on the server, i had to remove the varibles at the top so i could send it
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local GetSpawnPartEvent = ReplicatedStorage.Events.CollectibleEvents.GetSpawnPart
local Player = Players.LocalPlayer
GetSpawnPartEvent.OnClientInvoke = function(part : Part)
if part then
print("Client Invoked for SpawnPartEvent")
part.Transparency = 0
part.CanCollide = true
else
warn("Part was given as nil")
end
end```
Then this is the local script for the player
I get the error that Part was given as nil @fair plover on the client side and idk how to fix it
what are u trying to make?
its a system like in the incremental games where parts spawn for the player and you go around collecting them
and each part spawned will need to be different for each player due to different values like spawn speed values rng factors e.g
i did this above and got different errors
ye, but thats cuz u are trying to find something that doesnt exist
yes but then how do you fix that
because if you can not make parts on the server how would you even verify them?
never did something like that, i would need to try to make it to know
yeah me either im kind of stuck been asking for help for days
but yeah thank you trying to help it means a lot
if you get any ideas feel free to let me know
i would use collection service
what is collection service?
its for making tags
like setting attribute
that would be a good idea to optimise it
DISCORD 📜
Join my Discord Community if you want scripting help, participate in events/challenges, and make friends!
https://discord.gg/WC6kPu5W5P
MEMBERSHIPS 🎁
Get Access To My Scripts + More Perks By Becoming a Channel Member! 👇
https://www.youtube.com/@BrawlDevRBLX/join
ADVANCED ROBLOX SCRIPTING SERIES 🔴
https://www.youtube.com/p...
Just learn to script
i do know how to script, ive been script for quite some time
im just asking for some help
Yeah but you dont know collection service and you put modules in serverscriptservice (Mostly in replicated storage but its fine too)
Ok so if its me then I would just send the spawn location to the server using remote function and then let the server create the part and then return the part and make it only visible to the player.
You can not return parts in remote functions…
I tried that above
@sullen crater i made it work
no way how?
yep
what did you use?
local spawnSite = workspace:WaitForChild("World"):WaitForChild("SpawnSite")
local coin = game:GetService("ReplicatedStorage"):WaitForChild("Coin")
local coinModule = require(script.Parent:WaitForChild("CoinsModule"))
local zonePosition = spawnSite.Position - Vector3.new(spawnSite.Size.X/2,0,spawnSite.Size.Z/2 )
while task.wait(2) do
if coinModule.actualCoins < coinModule.maxCoins then
local coinClone = coin:Clone()
coinClone.Parent = workspace
coinClone.Position = zonePosition + Vector3.new(math.random(2, spawnSite.Size.X), 2, math.random(2, spawnSite.Size.Z) )
end
end
this just for the spawn
i used a module script to handle how much coins i have and whats the max can i create
and used collection service for the coin thing
ahh i see
can i see the code?
and what about the coins module?
local module = {}
module.actualCoins = 0;
module.maxCoins = 2
return module
ahh right
okay one question about this though
actually i can do it
thank you so much
your a life saver
wait where did you put the collect script?
player
doesnt it need to be in server script service?
to handle the addition of coins
u cant put it in server, cuz the part just exist in your local
how do i prevent exploiting then?
and make it safe
:FireServer
but then on the server side
how do i prevent a exploiter from just fireing it
so like what checks do i do before i just give the player the rewards
then return its properties as a table But u already found a fix so its fine.
for some reason this doesnt work
i mean, with just copy pasting is not going to work, did u add the tag?
when you used touch is there a way to check if another part touchs it
not me
beacuse i was gonna use this radius to collect them
u can use .Magnitude
how long have u been scripting?
how did you do that
well couple years for lua but its very on off as i do lots of projects on different langagues
i started in 2022
just as i told u:
collection:GetInstanceAddedSignal("coin"):Connect(function(part)
addedEvent:FireServer()
part.Touched:Once(function(hit)
collectEvent:FireServer()
part:Destroy()
end)
end)
-- and on server side:
local addedEvent = game:GetService("ReplicatedStorage"):WaitForChild("Event"):WaitForChild("added")
local updateEvent = game:GetService("ReplicatedStorage"):WaitForChild("Event"):WaitForChild("update")
local collectEvent = game:GetService("ReplicatedStorage"):WaitForChild("Event"):WaitForChild("collect")
addedEvent.OnServerEvent:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local coinsModule = require(char:WaitForChild("CoinsModule"))
local textLabel = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextLabel")
coinsModule.actualCoins = coinsModule.actualCoins + 1
if coinsModule.actualCoins > coinsModule.maxCoins then
print("Hacking")
end
updateEvent:FireClient(player, coinsModule.actualCoins, coinsModule.maxCoins)
end)
collectEvent.OnServerEvent:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local coinsModule = require(char:WaitForChild("CoinsModule"))
local textLabel = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Frame"):WaitForChild("TextLabel")
coinsModule.actualCoins = coinsModule.actualCoins - 1
if coinsModule.actualCoins > coinsModule.maxCoins or coinsModule.actualCoins < 0 then
print("Hacking")
end
updateEvent:FireClient(player, coinsModule.actualCoins, coinsModule.maxCoins)
end)
thank you
what is the update event for?
update the textlabel
updateEvent.OnClientEvent:Connect(function(actual, max)
coinModule.actualCoins = actual
coinModule.maxCoins = max
textLabel.Text = tostring(actual .."/".. max)
local player = game.Players.LocalPlayer
local textLabel = player.PlayerGui.ScreenGui.Frame.TextLabel
textLabel.Text = tostring(actual.."/"..max)
end)