Local Script not running even though its under PlayerGui

I have a localscript that detects Events labeled “Interaction” under the mouses target. The issue is that the script isnt running at all. I thought it was an issue with the localscript’s parent at first, but i checked and the documentation says that it should run under PlayerGui. Anyone know whats up with this?

Code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

Player.CharacterAdded:Wait()
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character.HumanoidRootPart

local InteractionGui = script.Parent
local InteractionText = InteractionGui.InteractionText

local SelectionHighlight = script.SelectionHighlight

local RemoteEvent = script.RemoteEvent

local Interactions = {
	"Press [E] to interact",
	"Press [E] to pick up"
}

local CurrentInteraction = nil

print("Player:", Player)
print("Mouse:", Mouse)

RunService.RenderStepped:Connect(function()
	if Mouse.Target then
		local Distance = (Mouse.Target.Position - HumanoidRootPart.Position).Magnitude
		
		local Interaction = Mouse.Target:FindFirstChild("Interaction") Mouse.Target.Parent:FindFirstChild("Interaction")
		if (not Interaction) or Interaction == CurrentInteraction then return end
		
		if Interaction == CurrentInteraction then return end
		
		local InteractionDistance = Interaction:FindFirstChild("MaxDistance")
		if InteractionDistance then
			if Distance > InteractionDistance.Value then return end
		else
			if Distance > 6 then return end
		end
		
		CurrentInteraction = Interaction
		
		local InteractionType = Interaction:FindFirstChild("Type")
		if not InteractionType then return end
		
		InteractionText.Text = Interactions[InteractionType.Value]
		InteractionText.Visible = true
		SelectionHighlight.Adornee = Interaction.Parent
	else
		InteractionText.Visible = false
		SelectionHighlight.Adornee = nil
	end
	
	print(Mouse.Target)
end)

UserInputService.InputBegan:Connect(function(Input, Processed)
	if CurrentInteraction then
		if Input.KeyCode == Enum.KeyCode.E and not Processed then
			RemoteEvent:FireServer(CurrentInteraction)
		end
	end
end)

image

Edit: It turns out the scrip IS running, but it stops running after the character variable line. Is it not detecting the character loading?

Edit 2: i removed that wait() line and its running those print things. But its not running the print in the runservice.Stepped function? i dont know why

EDIT 3: OKAY SO IT IS WORKING, i didnt see the print cuz it didnt print when there was a mouse target for some reason. But now i know that the Gui Text and the highlight is not appearing. The actual interaction stuff is though.

okay im an idiot ignore this post. I didnt put a interaction type under the interaction

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.