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

Random Weapon On Spawn works but the weapons don't work how would I fix this?

I have a local script in the starterpack that puts a random weapon from a folder in replicated storage called "Weapons" but the weapons don't work when you spawn, the problem isn't in the weapon script because they do work when they are just in the starterpack

code:

Weapons = game.ReplicatedStorage.Weapons:GetChildren()
local Weapon = Weapons[math.random(1,#Weapons)]:Clone()
Weapon.Parent = game.Players.LocalPlayer.Backpack

1 answer

✓ Accepted answer

you're using local script, which is works only on "client" not on server, you better use remove events to make it work. The clone is not actually clone, it is just visual try to do this > create event named "WeaponEvent" and move it in repStorage

-- local script (in starter pack/starter gui)
local Event = game.ReplicatedStorage:WaitForChild("WeaponEvent")
Event:FireServer()


-- script (in serverscriptservice)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("WeaponEvent")

local function RWeapon(player)
Weapons = game.ReplicatedStorage.Weapons:GetChildren()
local Weapon = Weapons[math.random(1,#Weapons)]:Clone()
Weapon.Parent = game.Players:FindFirstChild(player.Name).Backpack

Event.OnServerEvent:Connect(RWeapon)

8 comments

0

Line 11 Weapons is underlined and it does not work

0

Shouldn't it be a variable?

0

Also should It be a remote event or a bindable event?

0

remote event, do "function RWeapon(player)" without local and "local weapons = game.ReplicatedStorage.Weapons:GetChildren()

0

error code: 15:29:35.063 - Requested module experienced an error while loading

0

dont remove local on function

0

I fixed it thank you alot

0

np

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