Currently I am trying to make a non-experimental mode wizard battle game. The player has a certain amount of magic points they can use for spells. They can chose between three spells. When they equip their wand, they should see a GUI pop up telling them what spell they have selected. When they click, if they have enough magic points, the spell that they chose should go into action. The game works when I test by clicking on the play button but not on ROBLOX. I don't think it is the magic points because that works on ROBLOX. Thanks.
Here is my LocalScript in the tool:
local eq = false
local event = script.Parent:WaitForChild("RemoteEvent")
local spells = {"Light Bomb", "Lighting Rod", "Tidal Wave"}
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
player.CharacterAdded:connect(function(character)
local spelltag = character:WaitForChild("SpellTag")
local spellgui = player.PlayerGui:WaitForChild("ScreenGui"):WaitForChild("SpellLabel")
local spell = spells[spelltag.Value]
spellgui.Text = spell
spelltag.Changed:connect(function()
if eq then
spell = spells[spelltag.Value]
spellgui.Text = spell
end
end)
local function onClick()
if spell == "Light Bomb" then
event:FireServer("Bomb", mouse.Hit)
elseif spell == "Lighting Rod" then
event:FireServer("Light", mouse.Hit, player)
elseif spell == "Tidal Wave" then
event:FireServer("Tidal", mouse.Hit, player)
end
end
tool.Activated:connect(onClick)
tool.Equipped:connect(function()
eq = true
spellgui.Visible = true
end)
tool.Unequipped:connect(function()
eq = false
spellgui.Visible = false
end)
end)
Here is the Server Script in the tool:
local event = script.Parent:WaitForChild("RemoteEvent")
local Connection
local magic = script.Parent.Parent.Parent.Character:WaitForChild("MagicTag")
function createBomb(location)
local bomb = game:GetService("ServerStorage"):WaitForChild("lightbomb"):Clone()
bomb.CFrame = location
bomb.Parent = game.Workspace
end
function createTidal(location, player)
local tidal = game:GetService("ServerStorage"):WaitForChild("tidalwave"):Clone()
tidal.CFrame = script.Parent:WaitForChild("MagicPart").CFrame
tidal:WaitForChild("NotKill").Value = player.Name
tidal:WaitForChild("BodyPosition").Position = location.p
tidal.Parent = game.Workspace
end
function raycast(location, player)
local ray = Ray.new(script.Parent:WaitForChild("MagicPart").CFrame.p, (location.p - script.Parent:WaitForChild("MagicPart").CFrame.p).unit * 300)
local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
local lightning = game:GetService("ServerStorage"):WaitForChild("lightning"):Clone()
lightning.Parent = game.Workspace
local distance = (script.Parent:WaitForChild("MagicPart").CFrame.p - position).magnitude
lightning.Size = Vector3.new(0.3,0.3,distance)
lightning.CFrame = CFrame.new(script.Parent:WaitForChild("MagicPart").CFrame.p, position) * CFrame.new(0,0, -distance / 2)
game:GetService("Debris"):AddItem(lightning, 0.1)
end
local function decideEvent(player, ...)
local tuple = {...}
if tuple[1] == "Bomb" then
if magic.Value >= 20 then
magic.Value = magic.Value - 20
createBomb(tuple[2])
end
elseif tuple[1] == "Tidal" then
if magic.Value >= 35 then
magic.Value = magic.Value - 35
createTidal(tuple[2], tuple[3])
end
elseif tuple[1] == "Light" then
if magic.Value >= 5 then
magic.Value = magic.Value - 5
raycast(tuple[2], tuple[3])
end
end
end
local tool = script.Parent
tool.Equipped:connect(function()
Connection = event.OnServerEvent:connect(decideEvent)
end)
tool.Unequipped:connect(function()
Connection:disconnect()
end)

1 comment
Thank you so much for that advice! I never would've thought why it didn't work!