Hey there,
I have a script that gives the player 1 leaderstat when it is touched but I am also trying to make it say in the chat “[Server]: Player just won!” But when I try and do it in the server script it says "StarterGui:SetCore must be called from a local script but when I try my script as a local script it wont give the player 1 leaderstat nor send the message.
Script:
amnt = 1
local debounce = false
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
local plr = part.Parent
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Wins")
if (score~=nil) then
if not debounce then
debounce = true
score.Value = score.Value + amnt
wait(60)
debounce = false
end
end
end
end
end
end
script.Parent.Touched:connect(onTouched)
Chat message:
game.StarterGui:SetCore( "ChatMakeSystemMessage", { Text = "[Server]: "..plr.Name.. " just won!", Color = Color3.fromRGB(255, 6, 51), Font = Enum.Font.Arial, FontSize = Enum.FontSize.Size24 } )
You could use FireAllClients() to fire every client and handle the message being shown inside of a local script that way, keep the leaderstats handling in the server script.
Alright thank you, so if I put the leaderstat thing and the chat message in 2 different scripts how would I get that the player touched the part in the 2nd script?
local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local wonEvent = repStorage:WaitForChild("Events"):WaitForChild("Won")
local playerDebounce = {}
function onTouched(part)
if part.Parent:FindFirstChild("Humanoid") then
local plr = players:GetPlayerFromCharacter(part.Parent)
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
if plr then
local leaderstats = plr:WaitForChild("leaderstats")
if leaderstats then
local score = leaderstats:WaitForChild("Wins")
local Credits = leaderstats:WaitForChild("Credits")
if score then
if table.find(playerDebounce, plr) then
return
end
table.insert(playerDebounce, plr)
wonEvent:FireAllClients(plr)
score.Value += 1
Credits.Value = Credits.Value + math.random(75, 100)
task.wait(60)
table.remove(playerDebounce, plr)
end
end
end
end
end
script.Parent.Touched:connect(onTouched)
local players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local wonEvent = repStorage:WaitForChild("Events"):WaitForChild("Won")
local playerDebounce = {}
function onTouched(part)
if part.Parent:FindFirstChild("Humanoid") then
local plr = players:GetPlayerFromCharacter(part.Parent)
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
if plr then
local leaderstats = plr:WaitForChild("leaderstats")
if leaderstats then
local score = leaderstats:WaitForChild("Wins")
if score then
if table.find(playerDebounce, plr) then
return
end
table.insert(playerDebounce, plr)
wonEvent:FireAllClients(plr)
score.Value += 1
task.wait(60)
for i, player in pairs(playerDebounce) do
if player == plr then
table.remove(playerDebounce, i)
end
end
end
end
end
end
end
script.Parent.Touched:connect(onTouched)