Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not working in a local script?

This script works in solo mode, but not in online mode. I tried putting it in a local script for the LocalPlayer to work, but the script doesn't execute.

regenTime = 5
model = script.Parent.Parent.Parent.Parent.Parent

Touched = false

script.Parent.Touched:connect(function(hit)
	if Touched == false then
		Touched = true
		wait()
		backup = model:Clone()
		backup.Parent = game.ReplicatedStorage
		model:Destroy()
		opened = game.ReplicatedStorage["OpenedChest1"]:Clone()
		opened.Parent = game.Workspace
		
		wait(1.4)
		opened["Unknown Fruit"]:Destroy()
		
		player = game.Players:FindFirstChild(hit.Parent.Name)
		lighting = game.Lighting:GetChildren()
		fruit = lighting[math.random(1, #lighting)]
		
		if player and fruit then
			fruit:Clone().Parent = player.Backpack
		end
		
		wait(2.5)
		opened:Destroy()
		
		wait(regenTime)
		backup.Parent = game.Workspace
		Touched = false
	end
end)

Anything I'm not familiar about? *Edited script

1 answer

✓ Accepted answer

LocalScripts don't work in Workspace

Either make sure that you get the Player from the Touched event (Millions of tutorials), or put the script in PlayerScripts/PlayerGui and reference the Part statically.

3 comments

0

still not working

0

To teach the unknowing, you have to start from the beginning.

0

You know, "Still not working" doesn't really help me help you.

This discussion is preserved as it was. New answers, comments, and votes are closed.