local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
local castButton = script.Parent
--[[
--GAME LOGIC--
press E to cast
click screen to select target or to cast at location (aoe for example)
click button to cast, press button for tablet/phone
]]
--Framework--
local function onButtonClick()
-- if target is a player and player.character.humanoid then
-- cast spell on player
-- elseif target is a monster and monster.health > 0 then
-- cast spell on monster
-- elseif spell is aoe then
-- cast spell at location of mouse if mouse.position == ground or floor location idk really
-- end
print("Button was clicked!")
end
local function onInputBegan(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.UserInputType == Enum.UserInputType.Keyboard or input.UserInputType == Enum.UserInputType.MouseButton1 then --do I need this line?
if input.KeyCode == Enum.KeyCode.E then
-- and target selected and target is player and player is attackable and not dead
-- cast spell on player
print("User pressed the "..tostring(input.KeyCode).." key!")-- checking the correct key was pressed
end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
-- if target is selectable and not dead
-- select target
print(input.UserInputType, " was clicked")
else
-- player is targetting ground to cast spell
-- if spell selected
--cast spell selected
print("No target selected, casting spell at location ")--add location check
end
end
end
end
castButton.MouseButton1Click:Connect(onButtonClick)
UIS.InputBegan:Connect(onInputBegan)
Mousebutton registers when I move around the screen. Other than that I’m hoping I have the right idea and I wanted to make sure. I’m interested to know whether there’s a better way for all this. I also realise that some of this will be to prompt the server for the game logic.