So I'm making a turn-based RPG and I want the combat to start when the player touches the enemy. And the way the player is attacking the enemy is it finds the enemy humanoid in the workspace and makes it take damage. But, the enemy name is not the word "enemy" all the time, meaning I can't just access the name of the enemy easily all the time.
So because of this, I decided to make a script that changes the value of a string in a Gui. And the name of this string is the enemy's name. (The Below code is the .Touched script that sets the value)
local CombatGui = script.Parent
local CurrentEnemyName = CombatGui.CurrentEnemyName
local debounce = false
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
hrp.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Enemy") and debounce == false then
print("Touched!")
debounce = true
script.Parent.Enabled = true
script.Parent.Parent.PlayerHealth.Enabled = true
CurrentEnemyName.Value = hit.Parent.Name
end
end)
local enemy = game.Workspace:FindFirstChild(CurrentEnemyName.Value)
local eHumanoid = enemy:WaitForChild("Enemy")
From the last 2 variables, I'm trying to find a model in the Workspace that has the same name as the enemy im touching, but I don't know how to do this. So if you kind people of Scripting Helpers could help me fix this, I would be eternally grateful! (I'm sorry if this was kind of long or confusing btw.)
