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

How do I use Vector3 to make a block summon infront of my character?

Asked by 6 years ago

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:

01local player = game.Players.LocalPlayer
02local character = player.CharacterAdded:wait()
03local humanoid = character.Humanoid
04local postion = character.Torso.Position
05 
06local activate = player.PlayerScripts.Sharingan.Activated
07local sound = player.PlayerScripts.Sharingan.Ssound
08local sound2 = player.PlayerScripts.Sharingan.SsoundDeactivate
09local sharingan = game.Workspace.Sharingan:Clone()  --how do I fix this?--
10local chakra = player.PlayerGui.SharinganImage.Chakra
11local chakraimage = player.PlayerGui.SharinganImage.ChakraText
12local mouse = player:GetMouse()
13 
14 
15 
View all 39 lines...
0
Mouse.KeyDown is deprecated. User#19524 175 — 6y
0
Try to use CFrame instead and does it set the parent to workspace, etc StayToasted 3 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Mouse.KeyDown is deprecated, so is :connect() and :wait(). Learn more on deprecation here.

The reason it clones to the position you spawned at, is because on line 4, you're automatically recording the position of your torso. It does not change when your position changes.

01local player = game:GetService("Players").LocalPlayer
02local character = player.Character or player.CharacterAdded:Wait()
03local userInputService = game:GetService("UserInputService")
04local humanoid = character.Humanoid
05-- local postion = character.Torso.Position
06 
07local activate = player.PlayerScripts.Sharingan.Activated
08local sound = player.PlayerScripts.Sharingan.Ssound
09local sound2 = player.PlayerScripts.Sharingan.SsoundDeactivate
10local sharingan = game.Workspace.Sharingan:Clone() 
11local chakra = player.PlayerGui.SharinganImage.Chakra
12local chakraimage = player.PlayerGui.SharinganImage.ChakraText
13local mouse = player:GetMouse()
14 
15userInputService.InputBegan:Connect(function(key, chatting)
View all 40 lines...
0
It would error at line 21, as position is now nil Amiaa16 3227 — 6y
0
wait but for your keydown method I dont know how to make multiple key buttons. I can only make one turbomegapower12345 48 — 6y
Ad
Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

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:

1local copy = sharingan:Clone()
2copy.Parent = workspace
3--if it is a model
4copy:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame * CFrame.new(0,0,5))
5--if it is a basepart
6copy.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,0,5)

Answer this question