Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with Local Scripting?

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

✓ Accepted answer

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()

3 comments

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?

1

You're connecting to Touched after you've already destroyed the part. That doesn't make any sense.

0

Didn't catch that at first, thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.