Putting scripts inside of a character from leaderstats

I want to achieve getting these scripts and activating them while detecting if the player has something in leaderstats.

i try to run this script and it does not work buut shows no errors in output
image
image


image

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

while true do
	local character = script.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	local replicated = game:GetService("ReplicatedStorage")
	local powerfolder = replicated.Powers
	local elementsfolder = powerfolder.Elements
	local bluelaserfolder = powerfolder.BlueLaserDude
	local lightningfolder = powerfolder.Lightning
	wait(0.8)
	if player.leaderstats.Power.Value == "Elements" then
		local fireballclone = elementsfolder.DetectFireball:Clone()
		local earthmaggicclone = elementsfolder.DetectEarthMagic:Clone()
		local icemagicclone = elementsfolder.InputDetector:Clone()
		fireballclone.Parent = character
		fireballclone.Enabled = true
		earthmaggicclone.Parent = character
		earthmaggicclone.Enabled = true
		icemagicclone.Parent = character
		icemagicclone.Enabled = true
	elseif player.leaderstats.Power.Value == "Lightning" then
		local chainclone = lightningfolder.ChainLightningClient:Clone()
		local normalclone = lightningfolder.InputDetectorL:Clone()
		local beamclone = lightningfolder.LightAttackClient:Clone()
		beamclone.Parent = character
		beamclone.Enabled = true
		normalclone.Parent = character
		normalclone.Enabled = true
		chainclone.Parent = character
		chainclone.Enabled = true
	else
		if character.DetectFireball then
			character.DetectFireball:Destroy()
		end
		if character.DetectEarthMagic then
			character.DetectEarthMagic:Destroy()
		end
		if character.InputDetector then
			character.InputDetector:Destroy()
		end
		if character.ChainLightningClient then
			character.ChainLightningClient:Destroy()
		end
		if character.InputDetectorL then
			character.InputDetectorL:Destroy()
		end
		if character.LightAttackClient then
			character.LightAttackClient:Destroy()
		end
	end
end

this script doesnt work^^

script.Parent.Activated:Connect(function()
	local char = script.Parent.Parent
	local hum = char:WaitForChild("Humanoid")
	local animation = hum:LoadAnimation(script.Use)
	local player = game.Players:GetPlayerFromCharacter(char)
	if char ~= nil then
		animation:Play()
		wait(1)
		script.Parent:Destroy()
		player.leaderstats.Power.Value = "Lightning"
	end
end)

this script works^^
i have not seen any solutions to my problem on the dev foruum, this is my first ever post so if i dont smth wrongg im sorry, im not that good at scripting

You’re destroying the parent of the script, which will also destroy the script itself, so I don’t think the bottom line below is running. I just tested it, and apparently the line below does still run before the script stops, but you should still put the destroy function at the bottom of the code either way if you’re okay with the script not running anymore eventually. If the script destroying itself isn’t the problem, could you further elaborate what part of the code doesn’t work?
Also, you shouldn’t really put screenshots of your code, and putting the code only once is fine.

you are trying to fix the code that does work, if you look at the lua code above it, tha tis my problem, i just wanted to give you all the info you need. it does give me the leaderstats value but there is a script in SSS that is supposed to ruun every 0.8 seconds to detect which scripts to take out and/or put in.

it is under ““3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?””

also, I’m pretty sure that even if the script is deleted it will run. I’m not sure. but I know there is no wait between them so they run at the same time. so it will never fail to give the leaderstat value. but I will add your suggestion in case

the only problem really is that is the scripts are not going into my character

im ggoingg to just try and redo usingg a event

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.