#Weird error

46 messages · Page 1 of 1 (latest)

dreamy hatch
#

I made a bandage script a little while ago and I cannot understand why it prints an error. Also I'm clicking on a damaged dummy.

Local script

local RemoteEvent = script.Parent.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(player, Humanoid)
    print(Humanoid)
    Humanoid.Health = 10
    script.Parent.Sound:Play()
    player.Character.CameraEvent:FireClient()
    wait(3)
    player.Character.CameraEvent:FireClient()
end)

Server script

local Animation = script.Parent.Fidgeting
local Player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
    local Target = game.Players.LocalPlayer:GetMouse().Target
    if Target.Parent:FindFirstChild("Humanoid") and Target.Parent.Humanoid.Health < Target.Parent.Humanoid.MaxHealth then
        script.Parent.RemoteEvent:FireServer(Player, Target.Parent.Humanoid)
        Player.Character.Humanoid.Animator:Destroy()
        Instance.new("Animator").Parent = Player.Character.Humanoid
        Player.Character.Humanoid.Animator:LoadAnimation(Animation):Play()
    end
end)

Prints this:
levka_321
Health is not a valid member of Player "Players.levka_321"

still flicker
dreamy hatch
#

dangit

still flicker
#

FireServer automatically sends the player

#

so you have 2 player arguments

#

your remote will be sending this OnServerEvent

#

RemoteEvent.OnServerEvent:Connect(function(player, player, Humanoid)

#

the first is the one passed for you

#

the second the one YOU passed

#

the third would be the humanoid

dreamy hatch
#

oh i get it now thanks!

still flicker
#

no worries

#

basically you don't have to send the player

#

is done for you

#

script.Parent.RemoteEvent:FireServer(Target.Parent.Humanoid)

#

will fix it

#

btw, that's a messy ass script 😅, consider cleaning it out

#

variables exist, use them

#

and give your code some breathing room

dreamy hatch
#

yea i figured that

still flicker
#
local Animation = script.Parent.Fidgeting
local Player = game.Players.LocalPlayer
local RemoteEvent = script.Parent.RemoteEvent


script.Parent.Activated:Connect(function()
    local Target = game.Players.LocalPlayer:GetMouse().Target

    if Target.Parent:FindFirstChild("Humanoid") and Target.Parent.Humanoid.Health < Target.Parent.Humanoid.MaxHealth then
        local TargetHumanoid = Target.Parent.Humanoid
        local MyHumanoid = Player.Character.Humanoid

        RemoteEvent:FireServer(Player, TargetHumanoid)
        MyHumanoid.Animator:Destroy()
        
        local NewAnimator = Instance.new("Animator")
        NewAnimator.Parent = MyHumanoid
        NewAnimator:LoadAnimation(Animation):Play()
    end
end)
#

cleaner, don't you think?

dreamy hatch
#

true

still flicker
#
  Instance.new("Animator").Parent = Player.Character.Humanoid
        Player.Character.Humanoid.Animator:LoadAnimation(Animation):Play()

btw

#

never ever

#

ever

#

ever

#

in your life do that again 🙂

dreamy hatch
#

i mean i dont know

#

what else you can do

still flicker
#

now you do 😄

#

what I did

#

use variables

dreamy hatch
#

hmm okay

still flicker
#

lol

#

btw

#

don't actually go and paste what I did in your script lol

#

you might brake something

#

cause I might have done a typo

#

or sum

#

just showcasing how you can clean it out

#

using variables

dreamy hatch
#

yea

#

true

#

thanks for explaining!