If statement meets all conditions, but isn't working

Im my game NFT simulator, you exchange your Etherius for Cash. At the stand though, whenever you touch the radius, nothing happens. The seller doesn’t say any dialogue, and no GUIs pop up.

Here is the code:

local chat = game:GetService("Chat")
local head = script.Parent.Parent.Decoration["etherius man"].Head
local rep = game:GetService("ReplicatedStorage")
local ethprice = script.Parent.Parent.Price.Value
script.Parent.Touched:Connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then
	local player = game.Players:FindFirstChild(hit.Parent.Name)
		if ethprice > 0 then
			if player.leaderstats.Etherius.Value > 0 and player.PlayerGui:FindFirstChild("NewSell") == nil then
				chat:Chat(head, "wanna exchange your etherius?")
				local sell = rep.GUIs.Sell:Clone()
				sell.Name = "NewSell"
				sell.EtheriusPrompt.TextLabel.Text = "Would you like to sell your etherius for $".. ethprice * player.leaderstats.Etherius.Value .."?"
				wait(1)
				sell.Parent = player.PlayerGui
				sell.EtheriusPrompt:TweenPosition(UDim2.new(0.5, -148, 0.5, -131), "Out", "Quint", 2, true)
			elseif player.leaderstats.Etherius.Value == 0 then
				chat:Chat(head, "you have no etherius to exchange.")
			end
		end
	end
end)

Basically, he’ll only talk to you if you have no Etherius or you do have Etherius but no GUI. However, he doesn’t speak, and the GUI doesn’t trigger. Any help would be appreciated!

The issue is you gotta really check the if statements meet the condition. I suggest printing it out before the if statement to see if it’s true.

local chat = game:GetService("Chat")
local head = script.Parent.Parent.Decoration["etherius man"].Head
local rep = game:GetService("ReplicatedStorage")
script.Parent.Touched:Connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then
	local player = game.Players:FindFirstChild(hit.Parent.Name)
local ethprice = script.Parent.Parent.Price.Value -- Remeasure the eth price
print(ethprice)--double make sure to debug
		if ethprice > 0 then
			if player.leaderstats.Etherius.Value > 0 and player.PlayerGui:FindFirstChild("NewSell") == nil then
				chat:Chat(head, "wanna exchange your etherius?")
				local sell = rep.GUIs.Sell:Clone()
				sell.Name = "NewSell"
				sell.EtheriusPrompt.TextLabel.Text = "Would you like to sell your etherius for $".. ethprice * player.leaderstats.Etherius.Value .."?"
				wait(1)
				sell.Parent = player.PlayerGui
				sell.EtheriusPrompt:TweenPosition(UDim2.new(0.5, -148, 0.5, -131), "Out", "Quint", 2, true)
			elseif player.leaderstats.Etherius.Value == 0 then
				chat:Chat(head, "you have no etherius to exchange.")
			end
		end
	end
end)
1 Like
  1. You need to define the parent of the GUI before you can add text to it, otherwise, it will not show.
  2. Improper string concatenation.
local sell = rep.GUIs.Sell:Clone()
sell.Name = "NewSell"
sell.Parent = player.PlayerGui		
sell.EtheriusPrompt.TextLabel.Text = "Would you like to sell your etherius for $"..tostring( ethprice * player.leaderstats.Etherius.Value).."?"
wait(1)

This is weird… I pasted in your version with the prints and it started working. I still need to fix a few bugs with it that are unrelated to this but thank you

It’s not weird, sorry didn’t explain it fully. Values are “Copied” from the moment they are accessed, that’s why I commented --Remeasure Moving the ethprice variable within the Touched event allows it to remeasure the new updated value, or else it will stay as zero.

local transparency = part.Transparency --is equal to zero

part.Transparency = 1 -- change to 1

print(transparency) -- Still remains zero
print(part.Transparency) -- is equal to one after change

The only thing that breaks this behavior are tables which are passed by reference.

TL;DR “Values” are copied except for tables.