When a car collides with an opponent, it tries to raise the driver’s kill score.
creator creation succeeded, but the actual leaderboard score does not go up.
— Error message
leadersstats are not a valid member of the model “Workspace”.Recruitment 123"
Start stacking
Leaderboard Script in line 'ServerScriptService.22
Stack End - Server
serverscripterservice in
local datastore =game:GetService("DataStoreService") :GetDataStore("PlayerStats")
game.Players.PlayerAdded:Connect(function(player)
local ls = Instance.new("Folder",player)
ls.Name = "leaderstats"
local Money = Instance.new("NumberValue",ls)
Money.Value = 0
Money.Name = "Money"
local Kill = Instance.new("NumberValue",ls)
Kill.Value = 0
Kill.Name = "Kill"
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:connect(function()
local creater = char.Humanoid:FindFirstChild("creator")
if creater then
local killplr = creater.Value --죽인플레이어 확인
if killplr then
killplr.leaderstats.Kill.Value += 1
end
end
end)
end)
local ownsSportcar = Instance.new("BoolValue", player)
ownsSportcar.Name = "ownsSportcar"
ownsSportcar.Value = false
game.ReplicatedStorage.RemoteEvent2.OnServerEvent:Connect(function()
if player.leaderstats.Money.Value >= 100 then
player.leaderstats.Money.Value -= 100
player.ownsSportcar.Value = true
end
end)
local MoneyData
local ownsSportcarData
local KillData
--데이터베이스 탐색
local success, errormessage = pcall(function()
MoneyData = datastore:GetAsync(player.UserId.."-Money")
KillData = datastore:GetAsync(player.UserId.."-Kill")
ownsSportcarData = datastore:GetAsync(player.UserId.."ownsSportcar")
end)
if success then
Money.Value = MoneyData
Kill.Value = KillData
ownsSportcar.Value = ownsSportcarData
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
datastore:SetAsync(player.UserId.."-Money",player.leaderstats.Money.Value)
datastore:SetAsync(player.UserId.."-Kill",player.leaderstats.Kill.Value)
datastore:SetAsync(player.UserId.."-ownsSportcar",player.ownsSportcar.Value)
end)
ServerStorage internal model car script
local Enabled = true
local function TagHumanoid(humanoid, player)
local creator_tag = Instance.new("ObjectValue")
local occupantHumanoid = script.Parent.Parent.Parent.Parent.DriveSeat.Occupant
local PlayerId = occupantHumanoid.Parent
creator_tag.Value = player
creator_tag.Name = "creator"
creator_tag.Parent = humanoid
creator_tag.Value = PlayerId
end
local function UntagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
script.Parent.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
local plr = game:GetService("Players")
if hit.Parent:FindFirstChild("Humanoid") and Enabled then --부딪힌 상대 데미지 입는양
Enabled = false
if script.Hit.Value == false then
script.Hit.Value = true
local number1 = math.floor(0.5 * script.Parent.AssemblyLinearVelocity.Magnitude)
local hum = hit.Parent:FindFirstChild("Humanoid")
hum.Health = hum.Health - number1
TagHumanoid(Humanoid, plr)
script.Hit.Value = false
wait(2)
Enabled = true
UntagHumanoid(Humanoid)
end
end
end)
I think I should recognize the workspace player and the game player the same way, but I don’t know what to do. Help me.