Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

4 comments

0

Is this a localscript or a serverscript?(Serverscript is Normal Script)

0

oh I figured out the answer, thx anyway

0

Too bad, later on you will figure out that it is only visible for you.

0

wait what do you mean? But if it was in a ServerScript, then I cant use keys...

1 answer

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)

3 comments

0

You can delete the question if you found the answer.

0

care to share?

0

ok I will share

This discussion is preserved as it was. New answers, comments, and votes are closed.