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

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

Asked by
FBS_8 25
4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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)
0
Line 11 Weapons is underlined and it does not work FBS_8 25 — 4y
0
Shouldn't it be a variable? FBS_8 25 — 4y
0
Also should It be a remote event or a bindable event? FBS_8 25 — 4y
0
remote event, do "function RWeapon(player)" without local and "local weapons = game.ReplicatedStorage.Weapons:GetChildren() digameschannel 44 — 4y
View all comments (4 more)
0
error code: 15:29:35.063 - Requested module experienced an error while loading FBS_8 25 — 4y
0
dont remove local on function digameschannel 44 — 4y
0
I fixed it thank you alot FBS_8 25 — 4y
0
np digameschannel 44 — 4y
Ad

Answer this question