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

Loop Script| Only Working In Studio?

Idea To make a player re equip the specified "Rifle" every time they unequipped the "Rifle"
Problem The Script Only works in studios, any ideas? :D
Code

toolBin = script.Parent
plr = game.Players.LocalPlayer
char = plr.Character
while true do
if toolBin:findFirstChild("Rifle") then
	toolBin:findFirstChild("Rifle").Parent = char
end
wait()
end

THANKS :D

2 answers

✓ Accepted answer

If the issue is latency, as mentioned by devSeldom, I would recommend doing the following:

toolBin = script.Parent
plr = game.Players.LocalPlayer
char = plr.Character or plr.CharacterAdded:wait()
while wait() do
	if toolBin:findFirstChild("Rifle") then
    		toolBin:findFirstChild("Rifle").Parent = char
	end
end

Why?

Due to the character sometimes being created before the scripts run, in Roblox Studio, plr.CharacterAdded:wait()sometimes permanently yields the script, which can be a real pain when testing.

1 comment

0

Why was this voted down? An explanation will help me to improve me answers.

game.Players.LocalPlayer.CharacterAdded:wait()

This is because of latency, the problem is that local scripts run before the character is loaded causing loads of problems.

1 comment

0

Add the code I made at the tip top of the script

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