#Incremental spawning system

1 messages · Page 1 of 1 (latest)

toxic yarrow
#

So i have a system for a incremental game where you collect items that spawn however im stuck. For storing and holding the coins what do i use? If i use a module script in startplayerscript, firstly the server can not access it. Secondly a exploiter would be able to manipulate it. so what do i do?

analog lantern
#

Firstly

#

You could just change the module script location to repliczted storage

#

And secondly, the exploiter cant require the module since we can require it only once (tho i think he can just create a local script with the function of the module and idk just change but idk)

#

Btw, when an exploiter change the module, the change is not working on the server (ig atleast)

toxic yarrow
analog lantern
#

Well

#

I used attributes

#

Like, you set attributes on the server (max amount for ex)

#

And you get them on client

#

Always verify attributes on server when you getting coins or idk something like that, cuz the client can exploit like you said

analog lantern
#

But the problem is that you spawn them locally

toxic yarrow
# analog lantern But the problem is that you spawn them locally

so a good example of a game like this is: https://www.roblox.com/games/120870800305934/UPD-4-5-Sticks-Incremental
or just search: Sticks Incremental

Roblox

🍃 How to Play Sticks Incremental 🍃

🌲 Collect sticks to buy powerful upgrades.
✨ Discover rare sticks to boost your strength even more.
📈 Progress through unique stages to unlock special upgrades.
🏆 Automate your land and rise to become the #1 stick collector!

👍 Drop a like and favourite the game to support future updates.

...

#

its pretty much the idea i wanna add

analog lantern
# toxic yarrow yes

Ye but, problem is that you can never trust the client, so you probably need to spawn the parts on server

toxic yarrow
#

locally spawned parts you collect e.g

toxic yarrow
analog lantern
#

I have a question

toxic yarrow
#

while keeping it fast

toxic yarrow
analog lantern
#

When the part spawn on client, how would the server be able to know that the part spawned ?

toxic yarrow
analog lantern
analog lantern
toxic yarrow
toxic yarrow
#

let me send my current code

analog lantern
#

I might be wrong with all I say btw, im not really experimented

toxic yarrow
#

Server Script

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local addedEvent = ReplicatedStorage.Events:WaitForChild("Added")
local updateEvent = ReplicatedStorage.Events:WaitForChild("Update")
local collectEvent = ReplicatedStorage.Events:WaitForChild("Collect")
local getDataKey = ReplicatedStorage.Events:WaitForChild("GetDataKey")
local setDataKey = ReplicatedStorage.Events:WaitForChild("SetDataKey")

addedEvent.OnServerEvent:Connect(function(player)
    local char = player.Character or player.CharacterAdded:Wait()
    local coinsModule = require(char:WaitForChild("CoinsModule"))
    local textLabel = player:WaitForChild("PlayerGui").CollectionCounter.CounterText
    
    coinsModule.actualCoins = coinsModule.actualCoins + 1
    print(coinsModule.actualCoins)
    textLabel.Text = coinsModule.actualCoins .. "/" .. coinsModule.maxCoins

    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").CollectionCounter.CounterText
    
    coinsModule.actualCoins = coinsModule.actualCoins - 1

    print("Coins", coinsModule.actualCoins)
    
    textLabel.Text = coinsModule.actualCoins .. "/" .. coinsModule.maxCoins

    if coinsModule.actualCoins > coinsModule.maxCoins or coinsModule.actualCoins < 0 then
        print("Hacking")
    else
        local inventory = getDataKey:Invoke(player, "Inventory")
        inventory.Apple += 1
        print(inventory.Apple)
        setDataKey:Fire(player, "Inventory", inventory)
    end
    updateEvent:FireClient(player, coinsModule.actualCoins, coinsModule.maxCoins)
end)```
#

Client Collect System

local collection = game:GetService("CollectionService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local player = script.Parent.Parent

local coinsModule = require(script.Parent:WaitForChild("CoinsModule"))

local addedEvent = replicatedStorage.Events.Added
local collectEvent = replicatedStorage.Events.Collect

collection:GetInstanceAddedSignal("coin"):Connect(function(part)
    addedEvent:FireServer()

    part.Touched:Once(function(hit)
        print("hit")
        print(hit.Name)
        collectEvent:FireServer()
        part:Destroy() 
    end)
end)```
#

Client Spawn System

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local spawnSite = Workspace.World.MainMap:WaitForChild("SpawningPart")
local coin = 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 ) 

local Player = Players.LocalPlayer

local SpawnSpeed = 2.4

Player:GetAttributeChangedSignal("SpawnSpeed"):Connect(function()
    SpawnSpeed = Player:GetAttribute("SpawnSpeed")
end)

while task.wait(SpawnSpeed) do
    if coinModule.actualCoins < coinModule.maxCoins then
        print(coinModule.actualCoins, coinModule.maxCoins)
        local coinClone = coin:Clone()
        coinClone.Parent =  workspace
        coinClone.Position = zonePosition + Vector3.new(math.random(2, spawnSite.Size.X), 1.5, math.random(2, spawnSite.Size.Z) )
    else
        warn("Max Coins", coinModule.actualCoins)
    end
end```
analog lantern
toxic yarrow
analog lantern
#

If the exploiters create a part on his client side, the server wont see this part

toxic yarrow
analog lantern
#

But like I said, dont trust 100% what I did, i dont know what i dont really know much too, i just tried to help

#

Hope someone that knows better can explains it

#

Like if spawning the parts on client is a problem?

#

But ig yes but idk

toxic yarrow
#

this is so much harder then it seems and its really bugging me

analog lantern
#

?

toxic yarrow
#

how would spawn parts at different times for each player

analog lantern
#

Hm

#

Why not creating a thread when a player joins thats a loop that create parts each x time, where x is the spawn rate of the player

#

Like : lua task.spawn(YourSpawnFunction)
On player added obviously

toxic yarrow
analog lantern
toxic yarrow
analog lantern
#

You dont have to "update" the thread, just make sure your function update it

#

For example in the while loop, you set back the spawnrate to a new one if the player have upgraded it

#

Like :

local playerSpawnRate = 3 -- seconds
while task.wait(playerSpawnRate) do
-- here you actualize your playerspawnrate variable, like : playerSpawnRate = Player:GetAttribute("SpawnRate")
-- function to spawn part or idk
end
#

I mean i really wrote this fast

#

Idk if you got it

#

@toxic yarrow

#

If no tell me

toxic yarrow
#

no i get it thanks

#

let me try spin something up

toxic yarrow
#

it seems to work thanks man

#

but i got another question

#

what would be the best way to add a collect system now?

analog lantern
#

You say like a zone where you collect

#

Or a touched event

toxic yarrow
#

not sure if you tried the game i linked

#

but like that

river cosmos
#

Y

#

A better method would be to spawn the parts on the client but have the part count on the server

analog lantern
analog lantern
river cosmos
#

A server sends a remote event to the client

#

If the client sends it back you count it down

analog lantern
river cosmos
#

Random

#

You cant really sexure that

#

Secure

analog lantern
toxic yarrow
river cosmos
#

The exploiter could teleport all the parts to him but either way its better than having hundeards of parts on the server destroying themselfs and cloning back in miliseconds

#

Especially models

analog lantern
river cosmos
#

What would that change?

#

The part spawns on the client

#

If the server does that memory leaks and server lag wouls become a problem

analog lantern
river cosmos
#

And youll jave to rekoin to new servers alot more often

analog lantern
river cosmos
#

Yes

toxic yarrow
#

okay so im confused

#

@river cosmos your saying client right

#

this is the code i used

river cosmos
#

Because cloning and destroying n stuff adds a little bit of memory or sum that you cant destroy unless you go into a new server

river cosmos
#

It will cause server lag

#

That means alot bigger delay in stuff

toxic yarrow
#

i had the issue where i was unable to keep track of how many parts where currently spawned across server and client

analog lantern
river cosmos
#

As the server get older it lags

#

Its just better to do it on the client, because of alot shorter delays and longer server life

#

That means more servers will be faster

#

Shorter delay

analog lantern
#

And like make players rejoins

river cosmos
#

Eh

analog lantern
#

Ruin the competivity

#

With other players

analog lantern
#

But maybe you could make some infos about like the part on server actually, like the part pos, the part type, etc.. and then fire it from server to client to make the client create the part but id'

river cosmos
#

The only stuff i see n stuff is handle the logic on the server and objects on client

#

I mean you could make this all server sided but ion recomend

toxic yarrow
#

and what do you recomend i do differently from my code?