#Coins script not working (no error)

1 messages · Page 1 of 1 (latest)

fleet current
#

Spawning script: (server)

local coin = game.ReplicatedStorage.Coin

while true do
local coinWorkspace = coin:Clone()
coinWorkspace.Parent = workspace
coinWorkspace.Position = Vector3.new(math.random(-100, 100), 5, math.random(-100, 100))
game.Debris:AddItem(coinWorkspace, 5)
task.wait(1)
end

Leaderstats script: (local)

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue")
coins.Parent = leaderstats
coins.Name = "Coins"

Collection script inside of the spawned coin: (local)

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local coin = script.Parent
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")

coin.Touched:Connect(function()
coins.Value += 1
coin:Destroy()
end)

Summary: The first script is suppose to spawn coins from replicated storage at a random place on the map (which works), the second creates leaderstats and a Coins IntValue within that (which also works), and inside of the cloned coins there are LocalScripts that are meant to wait for the leaderstats in the local player then the coins inside them, and when the coin is touched the value goes up, but this does not work.

hexed basin
#

i asume its in workspace?

fleet current
#

which one

hexed basin
#

local

fleet current
#

in server script service

#

wait

#

it's suppost to be starterplayerscripts?

hexed basin
#

well locals dont run in server script service

#

so it didnt run at all

#

but

#

u still shouldnt use local for this at all

fleet current
#

i have to get the player

hexed basin
#

yea u doing quite a few things wrong

#

basically everything u done should be on server

#

not client

fleet current
#

i have an idea

random scarabBOT
#

studio** You are now Level 4! **studio

hexed basin
#

unless u want the coin to be removed for only the collector, then u can kinda keep some code but its gonna be bit more code

fleet current
#

actually

#

it wouldn't work

#

lol

hexed basin
#

or just who touched it

fleet current
#

everyone

hexed basin
#

yea so u gonna do everything on server

#

do u know basics

#

or u used google for this

fleet current
#

i know the basics

hexed basin
fleet current
#

wait ima use playeradded

hexed basin
#

leaderstat script

#

make it server

#

and use playeradded

#

to create leaderstats

#

for the coin collect, also use server under part
.Touched event returns which part hit

So to get player u gonna do
local plr= Players:GetPlayerFromCharacter(hit.Parent)
if plr then
u got player now

fleet current
#

unknown global hit

#

coin.Touched:Connect(function()
local plr = Players:GetPlayerFromCharacter(hit.Parent)
if plr then
coins.Value += 1
coin:Destroy()
end
end)

#

@hexed basin

hexed basin
#

like i said

#

Touched gives u which hit

#

so do function(hit)

#

not ()

#

and u gonna get THAT players coin value

#

not some random mfs

#

id asume u didnt remove localplayer

#

based on the code

fleet current
#

k but how do i add the leaderstats to the player

hexed basin
#

like i said, with player added

#

your leaderstats code was almost ready

#

like 2 lines missing

ionic rivet
hexed basin
#

yes

#

i told him to go server

#

already

ionic rivet
#

oh god

hexed basin
#

hopefully he understood

#

well he put leaderstats script in local and in server script service

#

so i dont expect much

fleet current
#

thanks

#

i understand

#

it works now

hexed basin
#

everything?

#

show code

fleet current
#

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"

local coins = Instance.new("IntValue")
coins.Parent = leaderstats
coins.Name = "Coins"    

end)

hexed basin
#

good

fleet current
#

i didn't realise that i had to create the leaderstats inside of the function lol

hexed basin
#

can u show coin script

#

like pickup one

fleet current
#

local Players = game:GetService("Players")

local coin = script.Parent

coin.Touched:Connect(function(hit)
local plr = Players:GetPlayerFromCharacter(hit.Parent)
if plr then
local leaderstats = plr:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
coins.Value += 1
coin:Destroy()
end
end)

ionic rivet
hexed basin
#

bud

ionic rivet
#

This is very irregular RSC help channel behavior

hexed basin
#

rip my s5 ig

#

he definetly needs the 1/100th of milisecond speed increase

#

i apologise sir

ionic rivet
hexed basin
#

aint that worst

#

just setting .Parent is easier to learn ig

ionic rivet
#

I recall it being the same as setting the parent in the line after it

#

The only difference occurs if you start setting properties after setting the parent. And because of the 1 lined nature of the second param, you cannot set properties with it before setting the parent

#

That's were the main performance concerns come from