Have I missed an end) or an end?

Lol, So how do I fix that? I’m new to scripting.

first,

if you want to do math in lua you can do

Value.Value += 1 -- basically takes the value and adds by one
-- or --
Value.Value = Value.Value + 1

for if and elseif

if thisandthat then

elseif not then
-- elseif does not have an end after it
end

1 Like

I would recommend watching a couple tutorials on lua arithmetic and on lua in general

he has a beginners playlist which is very helpful (I don’t have the time to really explain everything i have in mind, but this playlist should cover all of it.)

Thanks a lot, This will definately help! :slight_smile:

1 Like

Sorry again but after doing everything I’m still getting a single end) having troubles

Here is the updated script:

--LeaderBoard Script:
game.Players.PlayerAdded:connect(function(p)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	stats.Parent = p

	local money = Instance.new("IntValue")
	money.Name = "Money" 
	money.Value = 10 -- You can change this to anything
	money.Parent = stats

	local Sell = game.Workspace.PlaceHolderSellPoint
	local Handle = game.ReplicatedStorage.Paper.Handle
	local Paper = Handle.Parent
	local Rarity = Handle.Rarity

	local function onPartTouched(Handle)
		print((Sell.Name .. " has touched " .. Handle.Name))
		if Rarity == "Common" then

			Paper:Destroy()	
			p.leaderstats.Money.Value += 2		

			elseif Rarity == "Common+" then
				Paper:Destroy()	
				p.leaderstats.Money.Va lue += 10
					

			elseif Rarity == "Rare" then
				Paper:Destroy()	
				p.leaderstats.Money.Value += 70
					
			elseif Rarity == "Rare+" then
				Paper:Destroy()	
				p.leaderstats.Money.Value += 170
				
			elseif Rarity == "Epic" then
				Paper:Destroy()	
				p.leaderstats.Money.Value += 500
			
			elseif Rarity == "Epic+" then
				Paper:Destroy()	
				p.leaderstats.Money.Value += 1250
			
			elseif Rarity == "Legendary" then
				Paper:Destroy()	
				p.leaderstats.Money.Value += 5000
				
			elseif Rarity == "Mythic" then
				Paper:Destroy()	 
				p.leaderstats.Money.Value += 30000
			
			 Sell.Touched:Connect(onPartTouched)	
			end
		end
	end
end)
  • Missing 2 ends
  • elseif, not else if
--LeaderBoard Script:
game.Players.PlayerAdded:connect(function(p)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	stats.Parent = p

	local money = Instance.new("IntValue")
	money.Name = "Money" 
	money.Value = 10 -- You can change this to anything
	money.Parent = stats

	local Sell = game.Workspace.PlaceHolderSellPoint
	local Handle = game.ReplicatedStorage.Paper.Handle
	local Paper = Handle.Parent
	local Rarity = Handle.Rarity

	local function onPartTouched(Handle)
		print((Sell.Name .. " has touched " .. Handle.Name))
		if Rarity == "Common" then
			Paper:Destroy()	
			p.leaderstats.Money.Value = 2+
			Sell.Touched:Connect(onPartTouched)

			if Rarity == "Common+" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 10+
				Sell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Rare" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 70+
				Sell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Rare+" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 170+
				Sell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Epic" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 500+
				Sell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Epic+" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 1250+
				ell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Legendary" then
				Paper:Destroy()
				p.leaderstats.Money.Value = 5000+
				Sell.Touched:Connect(onPartTouched)	
			elseif Rarity == "Mythic" then
				Paper:Destroy()	
				p.leaderstats.Money.Value = 30000+
				Sell.Touched:Connect(onPartTouched)	
			end
		end
	end
end)

Your code has a lot issues, in lua else if is elseif, lua has to close all the if statements it opens(not like python) using an end and to perform adding you should use the += operator which is equal with value = value+new. I fixed those issues and switched to a dictionary based solution, so the if statements aren’t needed anymore:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players") 

--you can get rid of the if statements using a dictionary
--[rarity] = value
local rarities = {
	["Common"] = 2,
	["Common+"] = 10,
	["Rare"] = 70,
	["Rare+"] = 170,
	["Epic"] = 500,
	["Epic+"] = 1250,
	["Legendary"] = 5000,
	["Mythic"] = 30000
}

Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder") 
	stats.Name = "leaderstats"
	stats.Parent = player 
	
	local money = Instance.new("IntValue") 
	money.Name = "Money"
	money.Value = 10 
	money.Parent = stats 
	
	local Sell = workspace.PlaceHolderSellPoint
	local Handle = ReplicatedStorage.Paper.Handle
	local Paper = Handle.Parent
	local Rarity = Handle.Rarity
	
	local function onPartTouched(hit) 
		print(Sell.Name.." has touched "..hit.Name) --double brackets aren't needed
		--checking if the character is the current player character(not another random character)
		local character = hit:FindFirstAncestorWhichIsA("Model") 
		if character ~= player.Character then return end 
		
		--character is the same, everything good
		
		local value = rarities[Rarity.Value] --StringValue.Value is the actual value, rarity is just the object 
		--no need to reference player.leaderstats.Money, we already have it as a variable
		money.Value += value --when adding a value, you should use the += operator(old+new) not value+ 
	end
	--the touched connection should be outside the onPartTouched function
	Sell.Touched:Connect(onPartTouched)
end)
1 Like

The code only deletes the paper, Dosent add any value.

My code isn’t deleting anything, and is adding the value, I assume the issue is another script interfering.

Oh okay but once the paper touches sell point there is no value added?

Are you getting any errors/prints in the console?

None at all. Nothing is currently working.

When paper hit sellpoint = delete paper, add value according to rarity

Script dosen’t work anymore. Not sure whats happening

If you want to add value, Do:

p.leaderstats.Money.Value += 2

Not

p.leaderstats.Money.Value = 2+



Try this code:

game.Players.PlayerAdded:Connect(function(p)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"
	stats.Parent = p

	local money = Instance.new("IntValue")
	money.Name = "Money" 
	money.Value = 10 
	money.Parent = stats

	local Sell = game.Workspace.PlaceHolderSellPoint
	local Handle = game.ReplicatedStorage.Paper.Handle
	local Paper = Handle.Parent
	local Rarity = Handle.Rarity

	local function PartTouched()
		if Rarity == "Common" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 2
		elseif Rarity == "Common+" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 10
		elseif Rarity == "Rare" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 70
		elseif Rarity == "Rare+" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 170
		elseif Rarity == "Epic" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 500
		elseif Rarity == "Epic+" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 1250
		elseif Rarity == "Legendary" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 5000
		elseif Rarity == "Mythic+" then
			Paper:Destroy()
			p.leaderstats.Money.Value += 30000
		end
	end
	Sell.Touched:Connect(PartTouched)
end)

Nope, It isnt deleting the paper or adding value to leaderstats

Updated something, Can you try again?

Here is a video, Hopefully this clears it up:

robloxapp-20220227-1341298.wmv (3.2 MB)

Where do you store Rarity, Is it in a Value?

u use end) when it has a bracket and a end when it doesnt have a bracket also try see which end comes 1st and which comes last