How can i make a lighting strike happen when the player holds a metal item for to long

How do i make a strike of lighting hit a player if they hold a metal object lets say cube


like this one i made in 5 seconds

and like 10 seconds later the get struck by a lighting model
image
(like this one)

tell how i’d do this im new to scripting

oh btw this is botw inspired

On the server, you could keep track of whenever a player equips and unequips tools. If a player equips a tool that you classify as metal and 10 seconds later, that specific tool instance is still equipped, spawn lightning on the player.

4 Likes

Not 100% sure if this will work I haven’t tested it but something like this:


local tool = script.Parent
local lightning = game.Workspace.Lightning

Tool.Unequipped:Connect(function()
lightning.Transparency = 1
end)
Tool.Equipped:Connect(function() 
    wait(10)
print("Lightning")
  lightning.Transparency = 0
wait(0.2)
 lightning.Transparency = 1
end)

where would this go?
SSS?
or RS

It would go inside of the tool I believe, its not the best script btw, but its a start for you

You can put this in a script inside the tool.

local runService = game:GetService('RunService')

local tool = script.Parent

local timeHeld = 0
local equipped = false

tool.Equipped:Connect(function()
   equipped = true
end)

tool.Unequipped:Connect(function()
   equipped = false
end)

runService.Heartbeat:Connect(function(deltaTime)
   if equipped then
      timeHeld += deltaTime
      if timeHeld >= 10 then -- Set this to time before lightning strike in seconds
         -- Strike the player with lightning
      end
   else
      timeHeld = 0
   end
end)
1 Like

Yeah thats a better script, sorry I just did it quickly

Oh no problem. Starter scripts are awesome :slight_smile:

This is an interesting question. You could just increase the probability of being struck by lightning the longer the player has the item out. And then decrease the chance once the item is put away or completely remove the chance if you don’t want a lightning strike to be possible once the item is put away.

I’m not aware of how to make an actual lightning strike. @evaera Is pretty knowledgeable regarding that though. It’s a pretty nice attention to detail though.

You could easily just tween the lightning strike and set each tweeninfo to have like 0.1 delay for the first, 0.15 delay for the second and so on so it slowly goes down to the floor if yk what I mean, and you could maybe for a split second turn it neon.

Edit: Sorry nvm a tween is unnecessary

i am having a pickle

so
bruh moment
nothing is happening

the script has no errors too

Theres nothing in the script that sets off the lightning that I see?

you could set the position of the lightning to the player’s or you can weld the lightning to the player.

You will need to come up with your own script for that, I just made a script that will fire a certain line after being held for 10 seconds or so

Yeah heres the script but where it makes the lightning sort of “appear”

put the lightning in replicated storage

local runService = game:GetService('RunService')

local tool = script.Parent
local lightning = game.ReplicatedStorage.Lightning --replace with the name and location of your lightning

local timeHeld = 0
local equipped = false

tool.Equipped:Connect(function()
	equipped = true
end)

tool.Unequipped:Connect(function()
	equipped = false
end)

runService.Heartbeat:Connect(function(deltaTime)
	if equipped then
		timeHeld += deltaTime
		if timeHeld >= 10 then -- Set this to time before lightning strike in seconds
			lightning.Parent = game.Workspace
			lightning.Transparency = 0
			wait(0.1)
			lightning.Transparency = 1
			lightning.Parent = game.ReplicatedStorage
		end
	else
		timeHeld = 0
	end
end)