If it doesnt how can I make it so whatever direction the player faces it shoots from the angle from the players right hand? I'm pretty basic in scripting i made this after like 30 minutes or an hour of the dev forum and youtube tutorials
The script (local):
local UIS = game:GetService("UserInputService") local mouse = game.Players.LocalPlayer:GetMouse() local debounce = false local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") --Animation local animInstance = Instance.new("Animation") animInstance.AnimationId = "rbxassetid://04160584403" local fireballAnim = humanoid:LoadAnimation(animInstance) local function shootFireball(caster, mousePos) if caster == player then game.ReplicatedStorage.Events.FireBall:FireServer("Replicate",mousePos) --Show fireball for other players end local effects = game.ReplicatedStorage.FireBallEffects local fireBall = effects.FireBall:Clone() local explosion = effects.Explosion:Clone() local character = caster.Character --Fireball fireBall.Position = character.RightHand.Position fireBall.Parent = workspace fireBall.Sound:Play() local weld = Instance.new("WeldConstraint", fireBall) weld.Part0 = fireBall weld.Part1 = character.RightHand wait(0.45) weld:Destroy() local velocity = Instance.new("BodyVelocity", fireBall) velocity.Velocity = CFrame.new(fireBall.Position, mousePos).LookVector * 100 --Explosion fireBall.Touched:Connect(function(hit) if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end explosion.Position = fireBall.Position fireBall:Destroy() explosion.Parent = workspace explosion.Sound:Play() if caster == player then --Make sure the damage doesnt activate when someone else casted game.ReplicatedStorage.Events.FireBall:FireServer(hit) end wait(1) explosion:Destroy() end) end --PC UIS.InputBegan:Connect(function(key, processed) if processed or debounce then return end debounce = true if key.UserInputType == Enum.UserInputType.Keyboard then if key.KeyCode == Enum.KeyCode.One then fireballAnim:Play() wait(0.75) shootFireball(player, mouse.Hit.Position) end end wait(1) debounce = false end) --Mobile function onKeyPress(actionName, userInputState, inputObject, position, processed) if processed or debounce then return end debounce = true fireballAnim:Play() shootFireball(player, mouse.Hit.Position) print("1 was pressed") wait(1) debounce = false end game.ContextActionService:BindAction("keyPressSpecialName", onKeyPress, true, Enum.KeyCode.C) game.ContextActionService:SetPosition("keyPressSpecialName", UDim2.new(.5,0,-.5,0)) game.ContextActionService:SetImage("keyPressSpecialName", "rbxassetid://73737626") game.ReplicatedStorage.Events.FireBall.OnClientEvent:Connect(function(caster, mousePos) if caster == player then return end --The person casting the fireball can already see it shootFireball(caster, mousePos) --Create the fireball end)
Please search for you answer before posting to reduce duplicated posts.
brycee_o Programmer
Feb '18
Works the same on both platforms, mouse position(X,Y) & mouse.Hit work as well
https://devforum.roblox.com/t/how-do-i-get-mouse-hit-p-on-touch-devices/96939/