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

Help with Local Scripting?

Asked by
Scootakip 299 Moderation Voter
8 years ago
local p = game.Players.LocalPlayer.Character


local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.KeyDown:connect(function(Key)
    if Key == 'l' then
    if game.Players.LocalPlayer.MO.Value == "Fire" then
    local Part = Instance.new("Part")
    local Fire = Instance.new("Fire", Part)
    Fire.Size = 1
    Fire.Heat = 1
        Part.Shape = "Ball"
        Part.BrickColor = BrickColor.new("Really red")
        Part.Size = Vector3.new(1,1,1)
        Part.Parent = game.Workspace
        Part.Position = p.Torso.Position + p.Torso.CFrame.lookVector*5 
        Part.Velocity = p.Torso.CFrame.lookVector*5  * 40 + Vector3.new(0,40,0)
        Part.BottomSurface = "Smooth"
        Part.TopSurface = "Smooth"
        wait(5)
        Part:Destroy()
        Part.Touched:connect(function(hit)
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid ~= nil then
        humanoid.Health = 0
        end
end)
        end
end
end)

I find this issue odd, but whatever. The issue is that the script can't find 'p' in line 18. Yes, this script is inside of a LocalScript. This issue also doesn't happen in offline-testing, I only get this issue with server testing. Some help with this issue? The LocalScript is inside of the StarterGui.

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

Scripts run on the client before the character is created, so you can't directly get the character right away. Instead, do this:

local Player = game.Players.LocalPlayer
local p = Player.CharacterAdded:wait()
0
Neat, it works now, thanks! One more issue, the part where it's supposed to kill doesn't work and there aren't any messages about it in the output. Some help with that? Scootakip 299 — 8y
1
You're connecting to Touched after you've already destroyed the part. That doesn't make any sense. 1waffle1 2908 — 8y
0
Didn't catch that at first, thanks. Scootakip 299 — 8y
Ad

Answer this question