4667hp
(Account Info)
April 3, 2022, 10:28pm
#1
Hello. I’m getting the error *Unable to cast value to Object * coming from line 6 of this server script
The code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
script.Parent.Touched:Connect(function()
RemoteEvent:FireClient(script.Parent.Name)
end)
Is that the full code? Can you point where the line 6 is?
2 Likes
4667hp
(Account Info)
April 3, 2022, 10:34pm
#3
I have this code in a Gui
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local CodesGUI = script.Parent
local Notification = script.Parent.Notification
local RemoteEvent = ReplicatedStorage.RemoteEvent
RemoteEvent.OnClientEvent:Connect(function(Area, Player)
local newNotification = Notification:Clone()
newNotification.Name = "Notification2"
newNotification.Position = UDim2.fromScale(0,-0.1)
newNotification.Text = Area
newNotification.Visible = true
newNotification.Parent = CodesGUI
local FadeTween = TweenService:Create(newNotification, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {TextTransparency = 1})
newNotification:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Bounce, 0.5, false, function()
task.wait(0.5)
FadeTween:Play()
FadeTween.Completed:Wait()
newNotification.Visible = false
newNotification:Destroy()
end)
end)
I see the problem, you are firing a remote event using a string, the first argument must be an Instance and more specifically a player
2 Likes
You have to fire the player Argument first before the Part Name.
local RemoteEvent = ReplicatedStorage.RemoteEvent
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
RemoteEvent:FireClient(Player, script.Parent.Name)
end)
1 Like
4667hp
(Account Info)
April 3, 2022, 10:53pm
#6
now I am getting this error
The first argument you are sending isn’t a player
1 Like
This is because the touch event was probably touched by a normal part (A brick, the baseplate etc…) and since that isn’t a player then the “Player” variable is nil. Because of this it tells you that it is an invalid argument
2 Likes