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:
01 | local player = game.Players.LocalPlayer |
02 | local character = player.CharacterAdded:wait() |
03 | local humanoid = character.Humanoid |
04 | local postion = character.Torso.Position |
05 |
06 | local activate = player.PlayerScripts.Sharingan.Activated |
07 | local sound = player.PlayerScripts.Sharingan.Ssound |
08 | local sound 2 = player.PlayerScripts.Sharingan.SsoundDeactivate |
09 | local sharingan = game.Workspace.Sharingan:Clone() --how do I fix this?-- |
10 | local chakra = player.PlayerGui.SharinganImage.Chakra |
11 | local chakraimage = player.PlayerGui.SharinganImage.ChakraText |
12 | local mouse = player:GetMouse() |
13 |
14 |
15 |
Mouse.KeyDown
is deprecated, so is :connect()
and :wait()
. Learn more on deprecation here.01 | local player = game:GetService( "Players" ).LocalPlayer |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 | local userInputService = game:GetService( "UserInputService" ) |
04 | local humanoid = character.Humanoid |
05 | -- local postion = character.Torso.Position |
06 |
07 | local activate = player.PlayerScripts.Sharingan.Activated |
08 | local sound = player.PlayerScripts.Sharingan.Ssound |
09 | local sound 2 = player.PlayerScripts.Sharingan.SsoundDeactivate |
10 | local sharingan = game.Workspace.Sharingan:Clone() |
11 | local chakra = player.PlayerGui.SharinganImage.Chakra |
12 | local chakraimage = player.PlayerGui.SharinganImage.ChakraText |
13 | local mouse = player:GetMouse() |
14 |
15 | userInputService.InputBegan:Connect( function (key, chatting) |
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:
1 | local copy = sharingan:Clone() |
2 | copy.Parent = workspace |
3 | --if it is a model |
4 | copy:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new( 0 , 0 , 5 )) |
5 | --if it is a basepart |
6 | copy.CFrame = character.HumanoidRootPart.CFrame * CFrame.new( 0 , 0 , 5 ) |