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

Why does this script error out?

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)

1 comment

0

its erroring because u can't pass the player parameter

2 answers

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)

2 comments

0

That plr at the first line of the Client code is a bit pointless, but it should work.

0

oh yeah u right i instinctively wrote that lmao

--Script
local ClassicSword=game.ReplicatedStorage.ClassicSword
local player=script:FindFirstAncestorOfClass"Player"
script.Parent.MouseButton1Click:Connect(function() 
ClassicSword:Clone().Parent = player.Backpack
 end)

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