Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

If statement not working in text box ? [ANSWERED]

local script inside text box, no errors in output and it will not clone the pet inside player character after the text inside text box is test

local pet = game.ReplicatedStorage:WaitForChild("Pet")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local text = script.Parent

if text.Text == "test" then
	local clone = pet:Clone()
	clone.Parent = char
end

1 comment

1

This code is not being ran in a event so it will only be ran once. You should use the changed event or GetPropertyChangedSignal

1 answer

✓ Accepted answer

Like Kingdom5 said, your code was only going to run once since there was nothing calling it except your GUI loading. That's fine if that was your intention, but otherwise, you'll need an event to fire every time you type in that text box to re-run your code.

local pet = game.ReplicatedStorage:WaitForChild("Pet")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
local TextBox = script.Parent
local Keyword = 'test'

-- On Text Changed compare live
TextBox:GetPropertyChangedSignal('Text'):Connect(function()
	-- If you don't want the player to mass spawn pets
	local HasPet = Character:FindFirstChild(pet.Name)
	-- Compare Keyword with TextBox.Text
	if TextBox.Text == Keyword and not HasPet then
		-- Clone Pet to Character if they match
	    pet:Clone().Parent = Character
	end)
end

1 comment

0

i get it now ty

This discussion is preserved as it was. New answers, comments, and votes are closed.