Hello everybody!
I faced the problem that I don’t know how to make the script find the player in the workspace.
The script should do a simple thing, glue a small stick to the player’s hand, but this stick should not be a tool.
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player and player.Character
wait(5)
local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)
local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:clone()
ToolSharpening.parent = workspace.player
ToolSharpening.Positon = Vector3.new(workspace.player.RightHand.Position)
end)
Don’t ever use workspace.player. Use workspace:FindFirstChild(player.Name)
Edited script:
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player and player.Character
wait(5)
local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)
local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:clone()
ToolSharpening.parent = workspace:FindFirstChild(player.Name)
ToolSharpening.Positon = Vector3.new(workspace:FindFirstChild(player.Name).RightHand.Position)
end)
You should be using local Character = Player.Character or Player.CharacterAdded:Wait() to reference a player’s character model not workspace:FindFirstChild(Player.Name).
game.Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait() --Reference player's character with this.
task.wait(5) --Use 'task.wait' here.
local SharpeningUpgrdScript = require(game.ReplicatedStorage.sharpening.sharpening)
local SharpeningUpgrd = player.Tools.SharpeningUpgrd.Value
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ToolSharpening = ReplicatedStorage.SharpeningTool[SharpeningUpgrd]:Clone() --'clone' should be capitalised.
ToolSharpening.Parent = char --Use character reference from earlier.
ToolSharpening.CFrame = char.RightHand.CFrame --This is only going to be valid for 'R15' avatar types.
end)