✓ Accepted answer
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
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
local function CallResetOnPlayer(EnterPressed)
if not (EnterPressed) return end
RemoteEvent:FireServer(TextBox.Text)
end
TextBox.FocusLost:Connect(CallResetOnPlayer)
2 comments
Try this:
The Value must match the datatype, ensure you’re casting into a StringValue. Otherwise, take a look at my revised method below.