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

I cant find a fix im trying to make a a textbox and when you put die you die?

Asked by 2 years ago

local textbox = game.StarterGui.ScreenGui.TextBox local changed = textbox.Changed

changed:Connect(function() textbox.Text = ("die") if then script.Parent:Destroy() end

end)

0
game.startergui contains the instance(s) that gets copy-pasted to the playergui, it is not the same as game.players.player.playergui RAFA1608 543 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

GetPropertyChangedSignal fires if the property inside it changes

string.lower makes sure if player inputs ‘Die’, ‘diE’, or ‘die’, it all works.

Set local player’s hp to 0 if text passed the condition

local textbox = game.Players.LocalPlayer.PlayerGui:WaitForChild('ScreenGui').TextBox

textbox:GetPropertyChangedSignal('Text'):Connect(function()
    if string.lower(textbox.Text) == 'die' then
        game.Players.LocalPlayer.Character.Humanoid.Health = 0
    end
end)
0
Thank you aged_force9yt 0 — 2y
0
^Can you mark my answer as accepted if it helped? SuperLittleAdmin 257 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Maybe, it should be an event, like this

if textbox.Text == "Die" then
local plr = game.Players.LocalPlayer.Character
plr.Humanoid.Health = 0

Answer this question