Script not working. When touching part add +1 to gui

I am aware of that. But for starters, a simple .Touched is easier to understand and experiment with.

Also format code bc there are no (“end”)'s in it

For yours chickhenen would you put that in server script service???

You need to have a leaderstat script needs to have a RemoveEvent that gets fired everytime a player clicks/touches a button.

FireEvent

with the leaderstat script you should add

if “script here” 
then

leaderstat.Coins.Value + 1 

The first script would be in server script storage. The second would be in any part you want to give you coins when you touch

“local Players = game:GetPlayers()”
this would not work as you need to get the players, so

game.Players would work better.

“LeaderStats”
after this you checked for (“if leaderstats then”) this would not work too because you need to call the name you just assigned it.
(“if LeaderStats then”)

At the very bottom it says Coins.Value = Coins.Value + 1
this can be simplified into Coins.Value += 1

Also add ends into the code

1 Like

Thanks. I quickly made the script and I will apply your edits.

In the GUI you’ll get your leaderboard stat of how much coins with the FireEvent.

so in server script service do i get rid of all the other scripts which accord to this.

I have modified the script to work because when I tested the script, it did not work. Make sure to put it under the part you want to be touched

Code:

local Players = game.Players
local part = script.parent

local db = true

part.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then

		if not db then return end
		
		db = false

		local Player = Players:GetPlayerFromCharacter(hit.Parent)
		local LeaderStats =  Player:FindFirstChild("leaderstats")

		if LeaderStats then

			local Coins = LeaderStats:WaitForChild("Coins")

			Coins.Value += 1


			task.wait(2)
			db = true
		end
	end
end)
1 Like

Yeah Thanks! I’m on a vacation now so it’s kinda hard to type everything without being able to test it haha lol

It’s ok! Yeah it is hard to type on phone lol that would be torture.

1 Like

So the modified script have you condensed it into 1 script?

No, the first script I provided should be in server script storage. Here is it for convenience:


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.Value = 0
coins.Parent = leaderstats

end)

Then his script should be added in any part you want that gives you a point every time you touch it.

Thank you i will try it thanks for your help!!!

Also if you have more than like 5 parts needed to be touched it would be easier to make 1 script to control them all. Making a script for every part is very bad, but if it’s 1 part needed then you should be fine.

1 Like

image


image

1 Like

Since the other guy is on phone the quotations are weird. I also had to change them, use “Coins”.

Wait nevermind, just do it yourself it doesn’t work me mine either.

1 Like

Yeah and adding to that, I updated the script in server script storage. (Just change all quotation marks to your own
The leaderstats thing was named folder so I just changed that aswell

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	
	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Value = 0
	Coins.Parent = leaderstats
end)

Then:

local Players = game.Players
local part = script.parent

local db = true

part.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then

		if not db then return end
		
		db = false

		local Player = Players:GetPlayerFromCharacter(hit.Parent)
		local LeaderStats =  Player:FindFirstChild("leaderstats")

		if LeaderStats then

			local Coins = LeaderStats:WaitForChild("Coins")

			Coins.Value += 1


			task.wait(1)
			db = true
		end
	end
end)

Everything should be fixed

1 Like