I made a makeable burger now I want it to be able to sell when touched if the parent name is 'Normal Burger'

Here is the script:


script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent.Name == 'Normal Burger ' then
		local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if player then 
			player.leaderstats.Cash.Value =
player.leaderstats.Cash.Value +1
		end
	end
end)

PS. I am very new and barely know what I am doing/ D;

7 comments

1

I formatted your code because it wasn't in a code-block. I then realized you're missing an 'end' so I fixed it, if that's what you're looking for, try the code above again.

0

I tried the script nothing happened, the player.leaderstats.Cash.Value +1 bit is underlined in red and it is not telling me what is wrong

0

To properly modify a property, you can use the assignment operator, otherwise known as =. To perform an add-to operator—similarly seen as += in other languages—you have to take the current state of the value you with to increment and add to it; take the example below. 

0

player.leaderstats.Cash.Value = player.Leaderstats.Cash.Value + 1

0

Nevermind i fixed the red underline under the = but when the burger and the part touches it still isn't giving me any cash :(

0

Have you tried putting a print statement in the if statement to see if it runs? In the script above, you've included a white space when checking for the name("Normal Burger " instead of "Normal Burger"). Maybe this is what's causing the issue

0

i forgot how to add a print thing lol i give up i guess cause wasting to much of your guys time, but 1 last go Script: script.Parent.Touched:Connect(function(Hit) if Hit.Parent.Name == 'Normal Burger' then local player = game.Players:GetPlayerFromCharacter(Hit.Parent) if player then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1 end end end)