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

Why won't this give players a Pistol? [SOLVED]

game.Workspace.Guns.Changed:connect(function(t)
	if t == "Start" then
		local Player = game:GetService("Players").LocalPlayer
		local Item = game:GetService("ReplicatedStorage").Pistol:Clone()
		Item.Parent = Player.Backpack
	end
end)

In another script, I have something to change the Gun Value to "Start"

Oh, its in LocalScript too

2 comments

0

Anything in the output?

0

No, nothing

4 answers

✓ Accepted answer

Is filtering enabled? If so, make sure you are changing the Guns value client-side. If not then add some prints to see where the script stops. (Like 1 every line). So something like:

game.Workspace.Guns.Changed:connect(function(t)
    print("Value Changed")
    if t == "Start" then
        print("Value = Start")
        local Player = game:GetService("Players").LocalPlayer
        local Item = game:GetService("ReplicatedStorage").Pistol:Clone()
        print("Player defined, item cloned")
        Item.Parent = Player.Backpack
        print("Item parented")
    end
end)

8 comments

0

Ok, so nothing is coming through, so I am guessing that the LocalScript isnt even working. Any ideas? Is it possible to do the same thing in just a normal script?

0

Hm, where is the local script located? In StarterGui?

0

No, its in Workspace

0

That's the problem. Put it in StarterGui

0

so nothign was wrong with script, just has to be placed in starterGui?

0

Yup

0

for some reason now, if a player dies, they dont get their gun back. Anyway to make them so once they get the gun it stays with them until the other script removes the gun

0

Put it in there StarterGear as well.

Try putting it in ServerStorage.

4 comments

0

That doesn't work for LocalScripts. Descendants of ServerStorage are virtually invisible to LocalScripts.

0

yeah it didnt work

0

Can you answer my question? :l

0

Why are you asking that on here?

ServerScriptService will work?

1 comment

0

No it wont cause the pistol aint a script

Have you tryed putting

game.Workspace.Guns.Changed:connect(function(t)
    if t == "Start" then
        local Player = game:GetService("Players").LocalPlayer
        local Item = game:GetService("Lighting").Pistol:Clone() -- Changed to lighting. Remember to put the gun in there as well.
        Item.Parent = Player.Backpack
    end
end)

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