Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Loop Script| Only Working In Studio?

Asked by 8 years ago

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

Log in to vote
0
Answered by
Rhyles 80
8 years ago

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.

0
Why was this voted down? An explanation will help me to improve me answers. Rhyles 80 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
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.

0
Add the code I made at the tip top of the script User#5978 25 — 8y

Answer this question