generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Unable to cast value to Object?

Previous Thread :: Next Thread 
phoniex is not online. phoniex
Joined: 03 Feb 2008
Total Posts: 34985
24 Sep 2015 06:01 PM
This script gets this error at line 14. How do I fix it?

#code local tool = script.Parent
local user
local IgnoreList = {"Handle", "Hat"}


tool.Equipped:connect(function(mouse)

user = tool.Parent


mouse.Button1Down:connect(function()

local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray,{"Handle"})


local playerhit = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
if playerhit then
local humanoid = playerhit.Character.Humanoid
print(hit.Name)
if humanoid then
if hit.Name == "Head" then
humanoid:TakeDamage(100)
else
humanoid:TakeDamage(30)
end
end

-- Settings
local distance = (position - tool.AimPart.CFrame.p).magnitude
local rayPart = Instance.new("Part", user)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Really blue")
rayPart.Parent = game.Workspace
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, tool.AimPart.CFrame.p) * CFrame.new(0, 0, -distance/2)

game.Debris:AddItem(rayPart, 0.1)
end
end)
end)

http://www.roblox.com/item.aspx?id=147357900 http://www.roblox.com/e-item?id=289672302
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Sep 2015 06:01 PM
I means it wanted an Instance, and you gave it another type of value.
Report Abuse
phoniex is not online. phoniex
Joined: 03 Feb 2008
Total Posts: 34985
24 Sep 2015 06:04 PM
@Jarod

The purpose of the table part is to ignore Handles. Is there a way to do this?

http://www.roblox.com/item.aspx?id=147357900 http://www.roblox.com/e-item?id=289672302
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Sep 2015 06:04 PM
And I have no idea where the error is, since you only said "Line 14" which I have no idea about, but this is probably it.
"Handle"
It takes Instances, not strings.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Sep 2015 06:16 PM
Here, I worked up something to help with this.


local CastRay
CastRay = function(Origin, Direction, Distance, IgnoreList, IgnoreFunction)
local LeftOverDistance = 0
while Distance > 1000 do
LeftOverDistance = LeftOverDistance + 1000
Distance = Distance - 1000
end
local Hit, Pos, Surface = workspace:FindPartOnRay(Ray.new(Origin, Direction.Unit*Distance), IgnoreList, false)
if Hit then
if IgnoreFunction and IgnoreFunction(Hit) then
table.insert(IgnoreList, Hit)
return CastRay(Pos, Direction, LeftOverDistance + (Distance-(Origin-Pos).Magnitude), IgnoreList, IgnoreFunction)
end
end
if LeftOverDistance > 0 then
return CastRay(Pos, Direction, LeftOverDistance, IgnoreList, IgnoreFunction)
end
return Hit, Pos, Surface
end


Now just copy it, and use it like this:
local Hit, Pos = CastRay(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit, 300, {}, function(Part) if Part.Name == "Handle" then return true end end)
Report Abuse
phoniex is not online. phoniex
Joined: 03 Feb 2008
Total Posts: 34985
24 Sep 2015 06:18 PM
@Jarod

Where should I put those blocks of code, exactly?

http://www.roblox.com/item.aspx?id=147357900 http://www.roblox.com/e-item?id=289672302
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image