I am making a magic system in my RPG. The original script works very well on PC and I wanted to add mobile support. I got that bit sorted but on mobile I get the error in the title. I cannot find an alternative, I tried using UnitRay but that didn't work either. Any help is appreciated.
--// Services \\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService('Debris')
--// Variables \\--
local Remote = ReplicatedStorage.FireBallEvent
local FireBall = ReplicatedStorage.FireBall
local player = game.Workspace:FindFirstChild(game.Workspace.PlayerName.Value)
--// Settings \\--
local Damage = 20
local ServerDebounces = {}
Remote.OnServerEvent:Connect(function(plr, Mouse)
if not ServerDebounces[plr] then
ServerDebounces[plr] = true
local Char = plr.Character or plr.CharacterAdded:Wait()
local FireBallClone = FireBall:Clone()
FireBallClone.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new(0,0,-3)
FireBallClone.Parent = workspace
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BodyVelocity.Velocity = Mouse.lookVector ----- This is the problem line
BodyVelocity.Parent = FireBallClone
spawn(function()
for i = 0, 1000 do
wait()
FireBallClone.Size = FireBallClone.Size + Vector3.new(0.07,0.07,0.07)
BodyVelocity.Velocity = Mouse.lookVector*i
end
end)
ServerDebounces[plr] = false
Debris:AddItem(FireBallClone, 10)
local Debounce = true
FireBallClone.Touched:Connect(function(h)
if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then
Debounce = false
local Enemy = h.Parent.Humanoid
Enemy:TakeDamage(Damage)
FireBallClone.Transparency = 1
BodyVelocity:Destroy()
wait(1)
FireBallClone:Destroy()
wait(3)
Debounce = true
end
end)
end
end)

22 comments
I get: attempt to index nil with 'Hit'
and on PC it says: Hit is not a valid member of CFrame
Btw thank you so much for your Guardian Angel Defender plugin, I really appreciate it! You've helped me lots with it
Kinda random lol but i see the error in my code just change local Mouse_lookVector = (CharRP.Position - Mouse.Hit).unit to local Mouse_lookVector = (CharRP.Position - Mouse.Hit.Position).unit and it should work unless your script is not hooking up your mouse
I still get the same errors as before
I tried getting PlayerMouse in the local script but it also says that lookVector is not a valid member of PlayerMouse
hmm ill see if i can make a make a local script that uses the mouse hit and the centre point of the players character then use that vector as a direction creating a "lookVector". Ill post a link back here when its done
Hmm.. just a thought ... just before your error the Mouse.LookVector bit try printing out what Mouse value actually is. Something like print(Mouse) or even print(typeof(Mouse)) so we know what we're dealing with.
Got a little carried away with an example lol. Heres my script. https://bit.ly/2EaRxZa its a mockup of a wand script that shoots out yellow magic and it explodes on contact. The example is using that Mouse.hit Cframe as its base for the mouse direction. Hope this helps ya!
Thank you, I got the local script working very well. However, in the server script, it says "attempt to index nil with 'Hit'"
sounds like the server isnt seeing the Mouse object of the player.... Ill do a mockup of your server script and ill see if i can get it working with the code i provided for the client-local script. Is there anything else required to get the server script running? (other than the varables linked up in your script)?, If i get it working ill re-post what i have as an answer overriding my original.
Assuming i can lol
your server and a mockup client scripts should be on this answer as i've changed it completely with the working code examples!
Thank you very much! Got it working on mobile, all I have now is a PC error where it goes "invalid argument #3 (Vector3 expected, got CFrame)
At line 26
CFrame is composed of 2 vectors, 1 for position of the part and 1 for it's rotation CFrame.p turns the CFrame into a vector3 by only taking it's position values, the second vector is mouse.hit by combining them you get a new CFrame. From what I understand, we might need to change the values of MouseLV into a position?
I attempted to print out whatever MouseLV's value is and it's this: -9162.2207, 1422.07751, -1643.17358, 0.156244457, 0.132078186, 0.978847802, 5.69522381e-05, 0.991017878, -0.133729428, -0.987718403, 0.0209502354, 0.154833555 so I can see why the script is confused
And Im now getting the same error on both devices again lol. Everything else in the script appears to work very well though and I've connected my mobile script to the Mana bar successfully.
hmm.. are you on discord. or maybe robloxes team create thingy.if you like i could go over what you have and fix the problems.On the second note where you're getting the cframe errors just cast them to a vector3 by Vector3.new(CFrame). though it sounds like you may have a few loose ends in your client scripts.
Yeah I have discord, my alt user is: Lomando#7544
ok just sent you a friend request. im TGazza#8749
It’s accepted