Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

If statement not working in text box ? [ANSWERED]

Asked by 4 years ago
Edited 4 years ago

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
This code is not being ran in a event so it will only be ran once. You should use the changed event or GetPropertyChangedSignal User#5423 17 — 4y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
0
i get it now ty reformed_toshiro 7 — 4y
Ad

Answer this question