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

How to get text from textbox goto a bool value?

Asked by 4 years ago

So im making a gui where when you type a players name, It kills them, simple, but i dont know how to do this. How would i do this?

I've tried

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.vic.Value = script.Parent.Text
end)

how would i fix this?

Thanks,

0
Try this: Happy_Liam 64 — 4y
0
The Value must match the datatype, ensure you’re casting into a StringValue. Otherwise, take a look at my revised method below. Ziffixture 6913 — 4y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You’d need quite a lot more then that. To kill an avatar, you’d have to put that weight on the Server, as doing so locally won’t replicate to the victim nor the rest of the Clients; they will only die on your device. To solve this issue, we will have to perform the reset within a ServerScript bound by a RemoteEvent to a LocalScript.

The LocalScript is still required to handle the input.

Begin by placing a ServerScript within ServerScriptService and a RemoteEvent within ReplicatedStorage

--// ServerScript
local ReplicatedStorage = game:GetService("ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local Players = game:GetService("Players")

local function ResetGivenPlayer(_,TargetPlayer)
    if not (TargetPlayer) then return end
    local Player = Players:FindFirstChild(TargetPlayer)
    if (Player and Player.Character) then
        local Humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
        if (Humanoid) then
            Humanoid:TakeDamage(Humanoid.Health)
        end
    end
end

RemoteEvent.OnServerEvent:Connect(ResetGivenPlayer)

--// LocalScript

local ReplicatedStorage = game:GetService("ReplicatedStorage”)
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

local TextBox = script.Parent -- Should be a TextBox
--// MouseButton1Click can only be called on a GuiButton

local function CallResetOnPlayer(EnterPressed)
    if not (EnterPressed) return end
    RemoteEvent:FireServer(TextBox.Text)
end

TextBox.FocusLost:Connect(CallResetOnPlayer)
--// is conditioned to fire when we press return after typing out target
0
Thank you, This Helps a lot. EllaTheFloofyFox 106 — 4y
Ad

Answer this question