Hi, I am trying to make a script that makes a part (sharingan) summon in front of my player. But there is an issue, when ever I click F the part summons only on the position that I spawned on.
Extra Question: How do I make the sharingan clone properly. When I use :Clone() the sharingan does not clone itself and the sharingan also does not teleport.
But when I dont clone the sharingan, then the sharingan only teleports to the spawn.
Here is my script:
local player = game.Players.LocalPlayer local character = player.CharacterAdded:wait() local humanoid = character.Humanoid local postion = character.Torso.Position local activate = player.PlayerScripts.Sharingan.Activated local sound = player.PlayerScripts.Sharingan.Ssound local sound2 = player.PlayerScripts.Sharingan.SsoundDeactivate local sharingan = game.Workspace.Sharingan:Clone() --how do I fix this?-- local chakra = player.PlayerGui.SharinganImage.Chakra local chakraimage = player.PlayerGui.SharinganImage.ChakraText local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) if key == "f" then if activate.Value ==false then if chakra.Value > 50 then sound.TimePosition = 0 sound.Playing = true sharingan.Position = Vector3.new(postion) activate.Value = true print("ON!") --delete this soon-- humanoid.MaxHealth = 200 humanoid.Health = 200 humanoid.WalkSpeed = humanoid.WalkSpeed + 30 chakra.Value = chakra.Value - 50 chakraimage.Text = chakra.Value end else activate.Value = false print("OFF!") --delete soon!-- humanoid.MaxHealth = 100 humanoid.Health = 50 humanoid.WalkSpeed = 16 end end end)
Mouse.KeyDown
is deprecated, so is :connect()
and :wait()
. Learn more on deprecation here.local player = game:GetService("Players").LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local userInputService = game:GetService("UserInputService") local humanoid = character.Humanoid -- local postion = character.Torso.Position local activate = player.PlayerScripts.Sharingan.Activated local sound = player.PlayerScripts.Sharingan.Ssound local sound2 = player.PlayerScripts.Sharingan.SsoundDeactivate local sharingan = game.Workspace.Sharingan:Clone() local chakra = player.PlayerGui.SharinganImage.Chakra local chakraimage = player.PlayerGui.SharinganImage.ChakraText local mouse = player:GetMouse() userInputService.InputBegan:Connect(function(key, chatting) if key.KeyCode == Enum.KeyCode.E and not chatting then if not activate.Value then if chakra.Value > 50 then sound.TimePosition = 0 sound.Playing = true sharingan.Position = Vector3.new(postion) activate.Value = true print("ON!") --delete this soon-- humanoid.MaxHealth = 200 humanoid.Health = 200 humanoid.WalkSpeed = humanoid.WalkSpeed + 30 chakra.Value = chakra.Value - 50 chakraimage.Text = chakra.Value -- probably will want to position the sharingan here, idk. end else activate.Value = false print("OFF!") --delete soon! humanoid.MaxHealth = 100 humanoid.Health = 50 humanoid.WalkSpeed = 16 end end end)
First of all, after using Clone()
, you need to parent the copy back to workspace, as its initial parent is nil.
Now, to place the sharingan in front of the player, you need to set its CFrame
to the player's torso's CFrame * CFrame.new(0,0,i)
where i
is the number of studs away from the player's torso. Note that it has to be the Z axis, so the 3rd argument of CFrame.new()
.
So, properly done, it would look like this:
local copy = sharingan:Clone() copy.Parent = workspace --if it is a model copy:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new(0,0,5)) --if it is a basepart copy.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0,5)