Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm getting a 'Connect' error when everything in my script is correct?

Hello, I'm trying to make a system where, when you touch these parts, then it fires a remote event to the client and tweens the Gui on the screen. But, I'm getting an unknown 'Connect' error when the game starts, and before I got that error, whenever I tried to step on the parts, it didn't tween.

-- Server Script:

local BadBoyEvent = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("NPCRemotes"):FindFirstChild("BadBoyGUIFire")
local PartsStepped = workspace.Lobby:WaitForChild("TalkToNPC"):GetChildren()
local BadBoyDB = false

PartsStepped.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if not BadBoyDB and hum and plr then
		BadBoyDB = true
		BadBoyEvent:FireClient(plr)
		wait(2)
		BadBoyDB = false
	end
end)

-- Local Script:

local BadFrame = script.Parent:FindFirstChild("BadBoyFrame")
local BadBoyEvent = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("NPCRemotes"):FindFirstChild("BadBoyGUIFire")

local function TweenBadFrame(plr)
	BadFrame:TweenPosition(
		UDim2.new(0.044, 0,0.678, 0),
		"Back",
		"In",
		1,
		false,
		nil
	)
	
	print("The Bad Tween Frame was a Success!")
end

BadBoyEvent.OnClientEvent:Connect(TweenBadFrame)

Error: ServerScriptService.NPCTalkGUI:5: attempt to index nil with 'Connect' - Server - NPCTalkGUI:5

If you find a solution, please comment below!

2 comments

0

I think this is the solution, would you try going into settings and turning on HTTP services and the datastore services.

0

I already had that on but thanks for commenting!

1 answer

✓ Accepted answer

This should fix your errors, if there are still any errors let me know.

-- Server Script:

local BadBoyEvent = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("NPCRemotes"):FindFirstChild("BadBoyGUIFire")
local PartsStepped = workspace.Lobby:WaitForChild("TalkToNPC"):GetChildren()
local BadBoyDB = false

for _, part in pairs(PartsStepped) do -- we loop through every part in the PartsStepped folder/group
	part.Touched:Connect(function(hit) -- we call the touch event
		if hit.Parent:FindFirstChild("Humanoid") then
			local hum = hit.Parent:FindFirstChild("Humanoid")
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if not BadBoyDB and hum and plr then
				BadBoyDB = true
				BadBoyEvent:FireClient(plr)
				wait(2)
				BadBoyDB = false
			end
			
		end
	end)
end

-- Local Script

local player = game.Players.LocalPlayer
local BadFrame = script.Parent:FindFirstChild("BadBoyFrame")
local BadBoyEvent = game:GetService("ReplicatedStorage").RemoteEvents:WaitForChild("NPCRemotes"):FindFirstChild("BadBoyGUIFire")
local GOAL_POSITION = UDim2.new(0.044, 0,0.678, 0)

local function TweenBadFrame(plr)
	BadFrame:TweenPosition(
		GOAL_POSITION,
		Enum.EasingDirection.In, -- here you did "Back" when it's only a string and it will return as nil
		Enum.EasingStyle.Back, -- same here you put "In" and it will also return as nil
		1,
		false
	)

	print("The Bad Tween Frame was a Success!")
end

BadBoyEvent.OnClientEvent:Connect(TweenBadFrame)

1 comment

0

Thanks, although you can do string instead of Enum thing, the server script is the reason why it didnt work. Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.