I'm not really sure why this is happening, any help would be very much appreciated!

The script in the npc (fires when a player enters within a certain range):

wait(2)
local debounce = false
function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = 10000
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("HumanoidRootPart")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return torso
end
while true do
	if debounce == false then
wait()	
local torso = findNearestTorso(script.Parent.Parent.Torso.Position)
local Player = torso.Parent
local distance = CFrame.new(
	Vector3.new(torso.Position.X - script.Parent.Parent.Torso.Position.X,
		torso.Position.Y - script.Parent.Parent.Torso.Position.Y,
		torso.Position.Z - script.Parent.Parent.Torso.Position.Z))
if distance.X < 8 and distance.Y < 8 and distance.Z < 8 then
	name = game.Players.LocalPlayer
	parentName = script.Parent.Parent.Name
	game.ReplicatedStorage.stuff.namesTaken:FireClient(game.Players.LocalPlayer, parentName)
end
else wait()
end
end

Code for script inside of GUI that's within the ServerScriptService (sends GUI clone to the player within range):

local debounce = false
game.ReplicatedStorage.stuff.namesTaken.OnClientEvent:Connect(function(name, parentName)
	if debounce == false then
	debounce = true
	local s= script.Parent.Parent:Clone()
	s.Name = "Fight_New"
	s.Parent = game.Players:FindFirstChild(parentName).PlayerGui
	end
end)

3 comments

0

Youre using a remotevent thats a line between the server and the client u could also do a OnClientInvoke and u dont need to clone the gui to the player just put it on the backpack also in the replicatedstorate u need to wait for the event or function like game.ReplicatedStorage.stuff:WaitForChild("namesTaken").OnClientInvoke = function()

0
  1. That's irrelevant 2. Yes I do need to clone it, the GUI is reused 3. I'll check it out
0

Don't come on this site with free model code, expecting for it to be fixed.