-
What do you want to achieve? Hello, I’m trying to make a simple godmode script, I know there are better ways to do this but I’m pretty new to lua and I want to keep it simple. Anyways I need help to replace REPLACETHISTEXT with the text that the user put in TextBox.Text.
-
What is the issue? I don’t know how to insert the TextBox.Text into another line of code
-
What solutions have you tried so far? I looked around the hub, but i didn’t find any similliar posts.
I tried to put it in brackets but it didn’t work and I tried to just replace the REPLACETHISTEXT with TextBox.Text but It didn’t work…
So here is my code:
nameinput.Text is the TextBox.Text
execute is my TextButton
execute.MouseButton1Down:Connect(function()
Target = nameinput.Text
if Target == "andrejkooooo" then
People = game.Players.LocalPlayer.Character
game.Workspace.resources.events.humTakeDamage:FireServer(People.Humanoid, -99999999)
else
People = game.Players.REPLACETHISTEXT.Character
game.Workspace.resources.events.humTakeDamage:FireServer(People.Humanoid, -99999999)
end
end
Thank you!
2 Likes
You could do this
People = game:GetService("Players")[Target].Character
But this is prone to erroring if the given name is not ingame, so make sure you check that as well
People = game:GetService("Players"):FindFirstChild(Target)
if not People or not People.Character then
return
end
workspace.resources.events.humTakeDamage:FireServer(People.Character.Humanoid, -99999999)
1 Like
Thank you so much dude!
for anyone wondering this is the final script:
execute.MouseButton1Down:Connect(function()
Target = nameinput.Text
if Target == "andrejkooooo" then
People = game.Players.LocalPlayer.Character
game.Workspace.resources.events.humTakeDamage:FireServer(People.Humanoid, -99999999)
else
People = game:GetService("Players")[Target].Character
People = game:GetService("Players"):FindFirstChild(Target)
if not People or not People.Character then
return
end
workspace.resources.events.humTakeDamage:FireServer(People.Character.Humanoid, -99999999)
end
end)
1 Like
Do not include t hat line, it will error if you do not pass in a valid player name
1 Like
so i should use else or if or something like that?
No, all you need to do is remove the line I quoted, you just need the other lines that are after the else
execute.MouseButton1Down:Connect(function()
Target = nameinput.Text
if Target == "andrejkooooo" then
People = game.Players.LocalPlayer.Character
game.Workspace.resources.events.humTakeDamage:FireServer(People.Humanoid, -99999999)
else
People = game:GetService("Players"):FindFirstChild(Target)
if not People or not People.Character then
return
end
workspace.resources.events.humTakeDamage:FireServer(People.Character.Humanoid, -99999999)
end
end)
2 Likes
Okay, thanks so much mate! Have a good rest of your day! :))
2 Likes