If statement not working

I’m was trying to use an if statement to check for a value but on the first elseif it does not call that I checked and my value was equal to 1 can anyone help.

Thanks!

if Player.Trails.GrayTrail.Value == 0 then
	Status.Text = "Buy"
	Button.MouseButton1Click:Connect(function()
		if not debounce then
			debounce = true
			TrailBought:FireServer()
			PlusOne:FireServer()
			wait(0.1)
			debounce = false
		end
	end)
elseif Player.Trails.GrayTrail.Value == 1 then
	Status.Text = "Equip"
	Button.MouseButton1Click:Connect(function(player)
		local char = player.Character

		local attachment0 = Instance.new("Attachment")
		attachment0.Name = "TrailAttachment0"
		attachment0.Parent = char.Head

		local attachment1 = Instance.new("Attachment")
		attachment1.Name = "TrailAttachment1"
		attachment1.Parent = char.HumanoidRootPart

		Trail.Attachment0 = attachment0
		Trail.Attachment1 = attachment1
		Trail.Parent = char.Head
	end)
else
	Status.Text = "Equipped"
end
1 Like

What is this Value Property? its a property of what instance?

IntValue

Dont mind this over here.

Player.Trails I cant wrap my head around what your doing with that? ( Its just strange )

It is a folder inside the player.

I will just post the variables here

local Button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Trail = ReplicatedStorage.Trails.Gray:Clone()
local LPlayer = game:GetService("Players").LocalPlayer
local Price = Button.Price
local Status = Button.Status
local Player = Button.Parent.Parent.Parent.Parent
local TrailBought = ReplicatedStorage.BuysTrail
local debounce = false
local PlusOne = ReplicatedStorage.PlusOneGray

I mean your placing Trails within the Player Instance which is weird was it just to hold intvalues.

Lets get back to your if statements what isnt working?

Yes it was to just hold intvalues.
Dont mind the messiness. :sweat_smile:

It’s fine its not messy at all. I’m about to go could you tell which if statement isn’t working

Could it be this

if Player.Trails.GrayTrail.Value == 0 then

Do you receive any errors?

First i recommend placing some prints if you don’t have any errors. To debug

Would you mind showing the full script/code? I think there might be something wrong with the codes layout.

1 Like

There are no errors but it does not do what it is supposed to do when the value = 1

I did send the full thing it is just.

local Button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Trail = ReplicatedStorage.Trails.Gray:Clone()
local LPlayer = game:GetService("Players").LocalPlayer
local Price = Button.Price
local Status = Button.Status
local Player = Button.Parent.Parent.Parent.Parent
local TrailBought = ReplicatedStorage.BuysTrail
local debounce = false
local PlusOne = ReplicatedStorage.PlusOneGray

if Player.Trails.GrayTrail.Value == 0 then
	Status.Text = "Buy"
	Button.MouseButton1Click:Connect(function()
		if not debounce then
			debounce = true
			TrailBought:FireServer()
			PlusOne:FireServer()
			wait(0.1)
			debounce = false
		end
	end)
elseif Player.Trails.GrayTrail.Value == 1 then
	Status.Text = "Equip"
	Button.MouseButton1Click:Connect(function(player)
		local char = player.Character

		local attachment0 = Instance.new("Attachment")
		attachment0.Name = "TrailAttachment0"
		attachment0.Parent = char.Head

		local attachment1 = Instance.new("Attachment")
		attachment1.Name = "TrailAttachment1"
		attachment1.Parent = char.HumanoidRootPart

		Trail.Attachment0 = attachment0
		Trail.Attachment1 = attachment1
		Trail.Parent = char.Head
	end)
else
	Status.Text = "Equipped"
end

Outside the ifstatements i would add a print like so

print(Player.Trails.GrayTrail.Value)

then below

elseif Player.Trails.GrayTrail.Value == 1 then

I would add

warn("Value = 1") or print ("Value = 1")

Oh this code isn’t within any functions or events :eyes: is that intentional?

(It will only run once)

Is this a local script?

Yes it is a local script and I want it to only run once.

Try and check for spelling errors within the Player.Trails.GrayTrail.Value? It might be because you accidentally might’ve made a spelling error. This error is confusing towards me.

a.k.a GrayTrail.Name = "Gray Trail" which in this case would be Gray_Trail

No errors I did that more than 20 times.

You should try what I recommended and add prints so you can understand what’s happening more thoroughly.

It prints the value = 0 but it says 1 in the explorer.

Okay, This error seems confusing, hopefully someone else might try and resolve the error.