I am trying to make a script so that when the player clicks , it will create a ball/sphere from their head location ,but it does nothing when i test it.
here is the script
if mouseButton1OnClick:connect = true then function attack function()attack = end attack = game.Players.LocalPlayer.Character:findFirstChild("Head") Instance.new("Part") P=Part.Properties P.Properties.Anchored=false P.Vector3= 0,0,2 P.CanCollide=true P.Shape=Ball P.Size=5,5,5 P.Material= "SmoothPlastic" P.BrickColor="ReallyRed" P.transparency=.4 wait(5) end
A lot of mistakes. Let me fix it:
script.Parent.MouseButton1Down:connect(function() Local head = game.Players.LocalPlayer.Character:FindFirstChild("Head") If head then Local p = Instance.new("Part") P.Anchored=false P.Size = Vector3.new(5,5,5) P.CanCollide=true P.Shape = "Ball" P.CFrame = head.Position + Vector3.new(0,3,0) P.Material= "SmoothPlastic" P.BrickColor="Really red" P.Transparency= 0.4 wait(5) End end)
Script must be a LocalScript to use LocalPlayer.
This must be placed in a Local Script, and be replicated to a player service, like PlayerGui
or Backpack
.
player = game:GetService('Players').LocalPlayer mouse = player:GetMouse() mouse.Button1Down:connect(function() if (player.Character) and (player.Character:FindFirstChild('Head')) then local part = Instance.new('Part', game.Workspace) part.Size = Vector3.new(5, 5, 5) part.Vector3 = Vector3.new(0, 0, 2) part.Shape = Enum.PartType.Ball part.Material = Enum.Material.SmoothPlastic part.Transparency = .4 wait(5) part:Destroy() end end)