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

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

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?

1 comment

0

make sure FE is off

3 answers

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)

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).

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)

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