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 5 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:

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)

0
Mouse.KeyDown is deprecated. User#19524 175 — 5y
0
Try to use CFrame instead and does it set the parent to workspace, etc StayToasted 3 — 5y

2 answers

Log in to vote
0
Answered by 5 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.

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)
0
It would error at line 21, as position is now nil Amiaa16 3227 — 5y
0
wait but for your keydown method I dont know how to make multiple key buttons. I can only make one turbomegapower12345 48 — 5y
Ad
Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 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:

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)

Answer this question