Hello,
I've been struggling with this issue for a few days now... I made a tool, a potion that heals some of the player's damage when used. It works properly when placed in the starterpack, but errors (with the exact same script) when placed in the workspace (as I would like it to be a pickup tool and not a permanent item in the starterpack) But, the tool doesn't even show in the game and the script breaks on line3 (character = player.Character) saying "Character is not a valid member of DataModel. I've asked around but I can't seem to get a concrete answer. What am I missing/doing wrong?
local CanActivate = true local player = script.Parent.Parent.Parent or game.Players:GetPlayerFromCharacter(script.Parent.Parent) local character = player.Character
script.Parent.Activated:Connect(function() if CanActivate == true then CanActivate = false local animation = character.Humanoid:LoadAnimation(script.Parent.Animation) animation:Play() character.Humanoid.Health = character.Humanoid.Health + 25 print ("Health was restored by 25") wait(3) CanActivate = true script.Parent:Destroy() end end)
http://prntscr.com/ppfgrc
First Error Your error occurs in line 3. When you get the error: "Character is not a valid member of DataModel" it means that 'Character' can't be displayed/used in the data model you are doing/using.
Change line 3 to this:
-- -- local character = player.Name --- use .Name instead of .Character!
You can't use character as the value for a string; character isn't a string.
I hope I helped you.
http://prntscr.com/ppfmwa
Second Error
Your other error is that you define player as script.Parent.Parent.Parent. If the tool is in the Workspace, the player will NOT be script.Parent.Parent.Parent. You may need to do some if statements or :WaitForChild()s.
You need to locate the player and make sure script.Parent.Parent.Parent IS a player instance.