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

LocalScript gives tool in studio test mode but not in real play mode?

Asked by 7 years ago
Edited 7 years ago

So I am very new to scripting and I'm trying to make a tool move into a players starterpack when they press a button.

01local button = script.Parent
02local player = game.Players.LocalPlayer
03 
04button.MouseButton1Click:connect(function()
05    button.Parent.TextLabel.Visible = false
06    button.Visible = false
07    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
08    fireball.Parent = player:FindFirstChild("StarterGear")
09    wait(0.5)
10    player.Character.Humanoid.Health = nil
11end)

It works completely fine in studio test mode, however in play mode the player is reset, the gui on their screen disappears, but they don't get the tool?

The LocalScript is inside a button in StarterGui.

In play mode there is no error output in Client Log.

Edit - I want to keep the game with FE on, is there any fix?

0
make sure FE is off CootKitty 311 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago

This can be fixed by adding this little bit of code:

01local gui = button.Parent.Parent
02--change ^^ to the right path of the ScreenGui
03wait(0.2)
04local button = script.Parent
05local player = game.Players.LocalPlayer
06if not player.Character ~= nil then
07    gui.ResetOnSpawn = false
08    gui.Enabled = true
09end
10button.MouseButton1Click:connect(function()
11    button.Parent.TextLabel.Visible = false
12    button.Visible = false
13    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
14    fireball.Parent = player:FindFirstChild("StarterGear")
15    wait(0.5)
16    player.Character.Humanoid.Health = nil
17end)
Ad
Log in to vote
0
Answered by 7 years ago
01local button = script.Parent
02local player = game.Players.LocalPlayer
03 
04button.MouseButton1Click:Connect(function()
05    button.Parent.TextLabel.Visible = galse
06    button.Visible = false
07    local fireball = game.ReplicatedStorage:FindFirstChild("Fireball"):Clone()
08    fireball.Parent = player:WaitForChild("StarterGear")
09    fireball:Clone().Parent = player:WaitForChild("Backpack")
10end)

What I did was added another code, which is fireball:Clone().Parent = player:WaitForChild("Backpack") and removed line 10 because it actually kills the player. StarterGear is what holds tools a player will get everytime they die, but will not have the tool when given directly, so I added Line 6. Hope this helped. If you need more information, please either contact my through this comment or through ROBLOX (to message follow me).

Log in to vote
-1
Answered by 7 years ago

I'm not a pro scripter but put wait(1) at the start and then test it in multiplayer and see if it works. Sometimes in multiplayer the item you are trying to define isn't loaded and the script can't pass it because it sees it as an error.

01wait(1)
02local button = script.Parent
03local player = game.Players.LocalPlayer
04 
05button.MouseButton1Click:connect(function()
06    button.Parent.TextLabel.Visible = false
07    button.Visible = false
08    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
09    fireball.Parent = player:FindFirstChild("StarterGear")
10    wait(0.5)
11    player.Character.Humanoid.Health = nil
12end)

Answer this question