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

Why does this script error out?

Asked by
Cikeruw 14
1 year ago
Edited 1 year ago

I do not understand why it errors out when i do this i even tried player.Backpack instead of player.Character. Can someone help me

local ClassicSword = game.ReplicatedStorage.ClassicSword script.Parent.MouseButton1Click:Connect(function(player) local ClassicClone = ClassicSword:Clone() ClassicClone.Parent = player.Character end)

0
its erroring because u can't pass the player parameter ZeroToH3ro 82 — 1y

2 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

let me help u

  1. put ur sword in ReplicatedStorage

  2. create a RemoteEvent in ReplicatedStorage & name it "GiveSword"

  3. create a script in ServerScriptService & add the code below

local swordEvent = game.ReplicatedStorage.GiveSword
swordEvent.OnServerEvent:Connect(function(plr)
    local ClassicClone = game.ReplicatedStorage.ClassicSword:Clone()
    ClassicClone.Parent = plr.Backpack
end)

now create a local script under ur sword giver button (where u had ur original code) & add the code below

local swordEvent = game.ReplicatedStorage.GiveSword
script.Parent.MouseButton1Click:Connect(function()
    swordEvent:FireServer()
end)
0
That plr at the first line of the Client code is a bit pointless, but it should work. NotThatFamouss 605 — 1y
0
oh yeah u right i instinctively wrote that lmao ZeroToH3ro 82 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
--Script
local ClassicSword=game.ReplicatedStorage.ClassicSword
local player=script:FindFirstAncestorOfClass"Player"
script.Parent.MouseButton1Click:Connect(function() 
ClassicSword:Clone().Parent = player.Backpack
 end)

Answer this question