Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this raycasting script not work online? {Not Solved}

Asked by 9 years ago

When I test this when starting a server, it doesnt seem to work. I have NO clue why...

Here's how it works, in starter GUI there is a local script called "Gun" that creates a part, makes workspace its parent, and places the raycasting script (Which does damage) in the part. Keep in mind, "Gun" is a Local Script, and the raycasting script inside called "Raycast" is a normal script.

I TRIED USING A LOCAL SCRIPT, STILL DOESNT WORK. THE SCRIPT IS FULLY FUNCTIONAL

Here's the script:

local User
local Bullet = script.Parent
local LastPos = Bullet.Position
local RS = game:GetService("RunService").RenderStepped

while true do
local NewRay = Ray.new(LastPos, Bullet.Position - LastPos) --This casts a ray from the LastPos to the Bullet's current position
local H, P = game.Workspace:FindPartOnRay(NewRay, User)
local Human = H and H.Parent and H.Parent:FindFirstChild("Humanoid")
if Human then
local vPlayer = script.Parent.Owner.Value
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = script.Parent
tagHumanoid(Human)
Human:TakeDamage(10)
print("Hit")
untagHumanoid(Human)
script:Destroy()
end
LastPos = Bullet.Position --This resets the LastPos to the bullet's current position
RS:wait() --This waits for the RenderStepped event to fire, which is once every 1/60th of a second
end


function tagHumanoid(humanoid)
    -- todo: make tag expire
    local tag = script.Parent:findFirstChild("creator")
    if tag ~= nil then
        local new_tag = tag:clone()
        new_tag.Parent = humanoid
    end
end


function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then
            tag.Parent = nil
        end
    end
end 

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

I don't quite understand what you're trying to accomplish here.. Yes, presumedly you're trying to make a gun. But you're creating a part named gun into the Workspace and cloning the raycasting script into it? At the moment its just a brick in workspace raycasting in specified directions...

Also you're defining functions that you call in your While loop on line 6, post to having called them, in the loop.

If you're attempting to make a gun then just make a tool, and have the raycast script inside the tool but as a LocalScript, with Equipped, and Button1Down events.

0
Yea... I'm trying to bypass the "Tool" system. It's all scripted in the starter pack. Gun is not the name of the part, its a script that copies Raycast and places it into the brick. What raycast does is ever 1/60 second it sends a raycast from the bullets last position and current position to take damage of a object who has a humanoid in it when detected. Orlando777 315 — 9y
0
Something I just noticed, I copied and un-disabled the script. I added a print function in the while loop, and it seems that the while loop wont even execute (Having removed the other tagging functons) Orlando777 315 — 9y
Ad

Answer this question