Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need help with this "Get cash from coin script" whilist printing no errors?

Code:

coin = script.Parent

local player = game:GetService("Players")

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


-- Variables

game.Players.PlayerAdded:Connect(function()
	coin.Touched:Connect(function()
		player.leaderstats.Value = player.leaderstats.Value + 1
		wait(2)
		coin.Transparency = 1
	end)
end)

-- Function


print("Worked")

It printed 0 errors, please help!

3 comments

0

So is this script in the coin or serverscriptservice?  The leaderstats should be in the serverscriptservice and the touch to get money should be in the coin

0

Okay! Let me try it.

0

Didn't work

2 answers

—This should be in serverscriptservice

game.players.playeradded:Connect(function(player)

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

 local Coins = Instance.new(“IntValue”)
 Coins.Name = “Coins”
 Coins.Parent = leaderstats 

end)

—This should be in the coin

script.Parent.Touched:Connect(function(hit) local player = game.Players.FindFirstChild(hit.Parent.Name) player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10 -- Amount you get script.Parent.Parent = game.ServerStorage wait(5) -- how much seconds to wait after collecting again script.Parent.Parent = game.Workspace end)

1 comment

0

Didn't work / errored. Next time put it inside a code block.

this should be inside the server script service

game.Players.Playeradded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
	 leaderstats.Name = “leaderstats”
	 leaderstats.Parent = player
	 
	local Coins = Instance.new(“IntValue”)
	Coins.Name = “Coins”
	Coins.Parent = leaderstats
end)

this should be in the coin

Script.parent.Touched:Connect(function(hit)
	if game.Players:GetPlayerfromCharacter (hit.Parent) then
		local  TouchedPlayer = game.Players:GetPlayerfromCharacter (hit.Parent)
		local CoinValue = TouchedPlayer.leaderstats.Coins.Value
		CoinValue = CoinValue + 1
		Script.Parent:Destroy
	end
end)

i didn't test this so don't blame me if it doesn't work

3 comments

0

This should work sorry first time on this website still learning how to use it

0

The leaderstats worked after fixing many spelling errors. The other code did not work and errored multiple times with spelling errors

0

The leaderstats worked after fixing many spelling errors. The other code did not work and errored multiple times with spelling errors

This discussion is preserved as it was. New answers, comments, and votes are closed.