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)
#Can anyone please help me with this code
1 messages · Page 1 of 1 (latest)
whats wrong with it?
whats the output looking like?
Nothing the function doesn't even call
use
spawn(function()
-- Code
end
instead of task.spawn
it may work
Ok
Yup still not working
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
Local
Lemme check
thats what I am trying to get at as well lol
mhm mhm
Inside the coin in replicated storage
replicatedfirst
I'll let you take care of this since I am no pro myself ^_^
?
storage is for storing things
ReplicatedFirst is for scripts
its simillar to ServerScriptService
I know replicated storage is used to store things from local to server side
but for the client and modules
It is inside replicated storage
put it in ReplicatedFirst
So it doesn't work for local scripts
Ok
it is for local scripts and module scripts
Ok
Tried
No
spawn is depracted aswell
seems to be working for me
You need to update your luau vocabluary
Yes but its unsupported and not always may do.
i see
task.spawn is the new version
huh
I know
BodyPosition doesnt huh
Been using it since a year or two
im bad with roblox physics stuff 
Make it a global function
No ure just using outdated stuff
Idk why
Ok
You know what that means right
Yes that it works across the script
** You are now Level 9! **
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
Oh wow
Just remove local from local function
It should be able to call the function then
Remember to save them from the server