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

Why isn't a part summoning infront of my player?

Asked by 5 years ago

Hi, I made a script so that when a player clicks Z a part is supposed to summon infront of them... but for some reason the part summons only in the middle of the game, and nowhere else. Please help me!

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character.Humanoid
local torso = character.UpperTorso


local God = player.PlayerGui.ChooseCharacter.God
--BREAKLINE--

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        if inputObject.KeyCode.Name ==("E") then
    if God.Value ==("Zeus") then
        print("THUNDERBOLT!")
        local Thunder = Instance.new("Part",workspace)
        Thunder.CFrame = torso.CFrame + torso.CFrame.lookVector*-5 + torso.Position  --I think the error is here!--

    end

end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, 
   Enum.KeyCode.R,
   Enum.KeyCode.E)

0
Is this a localscript or a serverscript?(Serverscript is Normal Script) superalp1111 662 — 5y
0
oh I figured out the answer, thx anyway turbomegapower12345 48 — 5y
0
Too bad, later on you will figure out that it is only visible for you. superalp1111 662 — 5y
0
wait what do you mean? But if it was in a ServerScript, then I cant use keys... turbomegapower12345 48 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I FIGURED OUT THE ANSWER EVERYONE!

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local humanoid = character.Humanoid
local torso = character.UpperTorso


local God = player.PlayerGui.ChooseCharacter.God
--BREAKLINE--

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        if inputObject.KeyCode.Name ==("E") then
    if God.Value ==("Zeus") then
        print("THUNDERBOLT!")
        local Thunder = Instance.new("Part",workspace)
        Thunder.CFrame = character.Head.CFrame + character.Head.CFrame.lookVector*5 + torso.Position

    end

end
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, 
   Enum.KeyCode.R,
   Enum.KeyCode.E)

0
You can delete the question if you found the answer. Mr_Unlucky 1085 — 5y
0
care to share? xxXTimeXxx 101 — 5y
0
ok I will share turbomegapower12345 48 — 5y
Ad

Answer this question