#Can anyone please help me with this code

1 messages · Page 1 of 1 (latest)

fossil cargo
#
local RPS = game:GetService("ReplicatedStorage")
local coinTemplate = RPS.Coin
local player = game:GetService("Players").LocalPlayer



local function spawnCoin()
    local char = player.Character
    local root = char:FindFirstChild("HumanoidRootPart")
    if not root then return end
    local Coin = coinTemplate:Clone()
    Coin.Parent = game.Workspace
    Coin.Position = root.Position + Vector3.new(math.random(-10,10), 5, math.random(-10,10))
    Coin.Anchored = false
    
    Coin.Touched:Connect(function(hit)
        if hit:IsDescendantOf(char) then
            local stats = player:FindFirstChild("leaderstats")
            if stats and stats:FindFirstChild("Coin") then
                stats.Coin.Value += 1
                Coin:Destroy()
            end
        end
    end)
end
task.spawn(function()
    while true do
        task.wait(5)
        print("Called")
        spawnCoin()
    end
end)
shadow sentinel
#

whats the output looking like?

fossil cargo
native sequoia
#

instead of task.spawn

#

it may work

fossil cargo
#

Ok

fossil cargo
shadow sentinel
#

for starters @fossil cargo based on how you did this part
local player = game:GetService("Players").LocalPlayer

Are you using a server script or a Local script

fossil cargo
#

Local

native sequoia
#

wait

#

what is the script parented to

fossil cargo
#

Lemme check

shadow sentinel
#

thats what I am trying to get at as well lol

native sequoia
#

yeah

#

i saw what you were trying to do

shadow sentinel
#

mhm mhm

fossil cargo
#

Inside the coin in replicated storage

native sequoia
#

replicatedfirst

shadow sentinel
fossil cargo
native sequoia
#

storage is for storing things

#

ReplicatedFirst is for scripts

#

its simillar to ServerScriptService

fossil cargo
native sequoia
#

but for the client and modules

fossil cargo
#

It is inside replicated storage

native sequoia
#

put it in ReplicatedFirst

fossil cargo
#

Ok

native sequoia
#

it is for local scripts and module scripts

fossil cargo
#

Ok

fossil cargo
dusky coyote
#

spawn is depracted aswell

native sequoia
#

seems to be working for me

dusky coyote
#

You need to update your luau vocabluary

#

Yes but its unsupported and not always may do.

native sequoia
#

i see

dusky coyote
#

task.spawn is the new version

native sequoia
#

huh

fossil cargo
#

I know

dusky coyote
fossil cargo
#

Been using it since a year or two

native sequoia
dusky coyote
#

Idk why

fossil cargo
dusky coyote
fossil cargo
#

Yes that it works across the script

nocturne rampartBOT
#

studio** You are now Level 9! **studio

fossil cargo
#

So I should just remove local

#

Because I focus mostly on data stores

native sequoia
#

ServerScriptSerive - Only accessible from Server, usually Scripts and Module Scripts
ServerStorage - Same as ServerScriptService but code wont run
ReplicatedFirst - Accessible from both Client and Server usually to run Local Scripts (atleast what i use it for)
ReplicatedStorage - Same as ReplicatedFirst but code wont run

#

thats how i know them

fossil cargo
#

Oh wow

dusky coyote
#

It should be able to call the function then

dusky coyote
fossil cargo
#

Works

#

Ty

#

Now it's falling off the base plate