Unable to Cast Value to object

how do i get textlabel and textpartUi ?

local PortalHitbox = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("PortalHitbox")
PortalHitbox.OnClientEvent:Connect(function(TextLabel, TextPartUI, Inside)
	local TextPartLabel = TextLabel.Name
	local TextPartUIStroke = TextPartUI.Name
	
	if Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextPartLabel, TweenInfo.new(0.5), {TextTransparency = 0}):Play()
		TweenService:Create(TextPartUIStroke, TweenInfo.new(0.5), {Transparency = 0}):Play()
	elseif not Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextPartLabel, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
		TweenService:Create(TextPartUIStroke, TweenInfo.new(0.5), {Transparency = 1}):Play()
	end
end)
1 Like

So from looking at this I think I know what the problem is.

From looking at your code you try to change the TextTransparency of TextPartLabel, which is a string.

Try swapping out TextPartLabel with TextLabel, and swap TextPartUIStroke with TextPartUI when making the tweens

Doesn’t work, but can you update the code?

can you show me your updated code instead?

local PortalHitbox = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("PortalHitbox")
PortalHitbox.OnClientEvent:Connect(function(TextLabel, TextPartUI, Inside)
	local TextPartLabel = TextLabel.Name
	local TextPartUIStroke = TextPartUI.Name
	
	if Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextPartLabel, TweenInfo.new(0.5), {TextTransparency = 0}):Play()
		TweenService:Create(TextPartUIStroke, TweenInfo.new(0.5), {Transparency = 0}):Play()
	elseif not Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextPartLabel, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
		TweenService:Create(TextPartUIStroke, TweenInfo.new(0.5), {Transparency = 1}):Play()
	end
end)

Ok do you see where you use TweenService to create tweens, I want you to replace TextPartLabel amd TextPartUIStroke with TextLabel and TextPartUI

The reason is currently the code is trying to tween TextPartLabel amd TextPartUIStroke, which are both strings, and strings dont have a Transparency or TextTransparency property

local PortalHitbox = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("PortalHitbox")
PortalHitbox.OnClientEvent:Connect(function(TextLabel, TextPartUI, Inside)
	if Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextLabel, TweenInfo.new(0.5), {TextTransparency = 0}):Play()
		TweenService:Create(TextPartUI, TweenInfo.new(0.5), {Transparency = 0}):Play()
	elseif not Inside then
		local TweenService = game:GetService("TweenService")
		TweenService:Create(TextLabel, TweenInfo.new(0.5), {TextTransparency = 1}):Play()
		TweenService:Create(TextPartUI, TweenInfo.new(0.5), {Transparency = 1}):Play()
	end
end)

Like this?

Yup! That should do the trick.

If not could you tell me which line the error occurs on?

13:39:37.925 TweenService:Create failed because Instance is null

its on line 9

Ok looks like we got to do some debugging.

So the script that sends the RemoteEvent to the client, can I see the code? Specifically the code that triggers the RemoteEventHere:FireClient

image

local TextPartLabel = script.Parent.Parent.Text.SurfaceGui.TextLabel
local TextPartLabelUIStroke = script.Parent.Parent.Text.SurfaceGui.TextLabel.UIStroke
PortalHitbox:FireClient(player, TextPartLabel, TextPartLabelUIStroke, true)

Where is the script parented? Where is the Text part parented? (I assume workspace)
Have you tried waiting for the TextPartLabel to load in? Can I see the full code for the script?

--local varaibles
local Hitbox = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Text = script.Parent.Parent.Text
local TextPartLabel = Text.SurfaceGui.TextLabel
local TextPartLabelUIStroke = Text.SurfaceGui.TextLabel.UIStroke
---------------------------------------
--Settings

local HitboxRange = 35
---------------------------------------

--Apply Settings

Hitbox.Size = Vector3.new(HitboxRange,HitboxRange,HitboxRange)

---------------------------------------
--hitbox detect

while task.wait(0.1) do
	--if player in box
	local InsideParts = workspace:GetPartsInPart(Hitbox)
	for _, v in pairs(InsideParts) do
		if v.Parent:IsA("Model") then
			local humanoid = v.Parent:FindFirstChild("Humanoid")
			local player = game.Players:GetPlayerFromCharacter(v.Parent)
			if humanoid and player then
				local PortalHitbox = Remotes:FindFirstChild("PortalHitbox")
				PortalHitbox:FireClient(player, TextPartLabel, TextPartLabelUIStroke, true)
			end
		end
	end
	
	--if player not in box
	
	for _, player in pairs(game.Players:GetPlayers()) do
		if player.Character then
			local character = player.Character
			local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
			if humanoidRootPart and (humanoidRootPart.Position - Hitbox.Position).Magnitude > HitboxRange then
				local PortalHitbox = Remotes:FindFirstChild("PortalHitbox")
				PortalHitbox:FireClient(player, TextPartLabel, TextPartLabelUIStroke, false)
			end
		end
	end
end

Parent is on the TutorialPortal, on workspace
image

Portals Folder is in Workspace too.
image

Ok I would recommend trying to use :WaitForChild(‘’) When getting the TextLabel and stroke, example:

local Text = script.Parent.Parent:WaitForChild('Text',30)
local TextPartLabel = Text:WaitForChild('SurfaceGui',30).TextLabel
local TextPartLabelUIStroke = TextPartLabel.UIStroke

I forgot to tell that I used Wait For Child and still dont work but I think I could use module script and use fire client in there?

Is the ModuleScript required by a server script / script / regular script?

I havent created a module script yet, but what is Script and Regular Script?

well in roblox there are two types of scripts.

Local scripts, and scripts.
Scripts are also known as server scripts, or regular scripts.

Scripts are sometimes called Server Scripts as they run on the server, unless you change their RunContext property, which I have no idea how that works so we arent going into that one lol.

Should I place the module script in ReplicatedStorage or ServerScriptService?