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.

local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:connect(function()
    button.Parent.TextLabel.Visible = false
    button.Visible = false
    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
    fireball.Parent = player:FindFirstChild("StarterGear")
    wait(0.5)
    player.Character.Humanoid.Health = nil
end)

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:

local gui = button.Parent.Parent
--change ^^ to the right path of the ScreenGui
wait(0.2)
local button = script.Parent
local player = game.Players.LocalPlayer
if not player.Character ~= nil then
    gui.ResetOnSpawn = false
    gui.Enabled = true
end
button.MouseButton1Click:connect(function()
    button.Parent.TextLabel.Visible = false
    button.Visible = false
    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
    fireball.Parent = player:FindFirstChild("StarterGear")
    wait(0.5)
    player.Character.Humanoid.Health = nil
end)

Ad
Log in to vote
0
Answered by 7 years ago
local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    button.Parent.TextLabel.Visible = galse
    button.Visible = false
    local fireball = game.ReplicatedStorage:FindFirstChild("Fireball"):Clone()
    fireball.Parent = player:WaitForChild("StarterGear")
    fireball:Clone().Parent = player:WaitForChild("Backpack")
end)

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.

wait(1)
local button = script.Parent
local player = game.Players.LocalPlayer

button.MouseButton1Click:connect(function()
    button.Parent.TextLabel.Visible = false
    button.Visible = false
    local fireball = game:GetService("ReplicatedStorage"):FindFirstChild("Fireball"):Clone()
    fireball.Parent = player:FindFirstChild("StarterGear")
    wait(0.5)
    player.Character.Humanoid.Health = nil
end)

Answer this question