I don’t think @Nogalo’s solution fixes anything more than what we’ve gotten to, because the output doesn’t say it didn’t find anything with the player’s name. Speaking of the output, @JavaKingz would you mind doing print(Player.ClassName)
to make sure we’re dealing with the player and not the character?
I Tried it,but output kept sending me error
you should try moving the script to serverscriptservice or workspace, and not put it in PlayerStarterScripts
You should try to do print(Player.ClassName)
and tell us the results.
The problem is that the part is touching other parts when the game starts, so you need to check if the part is a descendant of a player’s character and get the player by doing local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
To make sure that the variable Player
is equal to something we do if Player then
, now that we know the variable Player
is equal to something, we check if it is a ‘Player’ by doing Player:IsA("Player")
, after we did that, we need to check if the Player is in the group and to do that we do Player:IsInGroup(7104281)
(hoped that help you understand it better)
good point, the part might be touching baseplate the whole time thus firing the error all the time
I disagree with the need to check the class because :GetPlayerFromCharacter()
will always return an instance of the class Player
if it’s not nil, hence rendering that bit useless.
Btw guys,Does the problem just because i using localscript?
I don’t think this is where the problem is emerging from, but I definitely suggest moving this to a server script, because it’ll be checking for every player not just one. There is a possibility that this is the root of the problem though.
Try just adding that
if Player then
--in group stuff and rest of code
end
That will fix it.
I recommend just copy and pasting the code into a script inside ServerScriptService. Also like @MrLonely1221 said, add the if Player then
thing if you haven’t already.
I can’t do that because there a ‘FireServer
’.
Would you mind showing us that part of the code so I can help you change it up? Mostly the part where the server receives it.
No need to have it under ServerScriptService, just have your script under your part. Also if you’re going to switch to the server, be aware of: .
Using this in a
Script
, as opposed to aLocalScript
, will not get you the most up-to-date information. If a player leaves a group while they are in the game, IsInGroup will still think they’re in that group until they leave. However, this does not happen when used with a LocalScript.
Remote events may be a workaround
I agree, but if he is using if Player then
then I really don’t have any other idea as to why this isn’t working.
This :
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit:FindFirstAncestorWhichIsA("Model") then
if Player then
if Player:IsInGroup(7104281) then -- Group ID
if hit.Name == "HumanoidRootPart" then
if ReadyToClaim == true then
local Coins = 1000
game.ReplicatedStorage.CoinGiver:FireServer(Coins)
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Come back in"
game.ReplicatedStorage.GiveChestData:FireServer(MinutesYouWantItToBe, SecondsYouWantItToBe, GroupHours)
repeat
ReadyToClaim = false
if GroupHours >= 1 then
if seconds <= 0 then
if minutes <= 0 then
GroupHours = GroupHours - 1
minutes = 59
seconds = 59
else
minutes = minutes - 1
seconds = 59
end
else
seconds = seconds - 1
end
else
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
end
if GroupHours <= 9 then
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
else
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
end
wait(1)
until GroupHours == 0 and minutes == 0 and seconds == 0
timer.Text = "claim your reward!"
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Ready to"
ReadyToClaim = true
game.ReplicatedStorage.GiveGroupData:FireServer(minutes, seconds, GroupHours)
end
end
end
end
end
end)
game.Workspace.GroupChest.TriggerPart.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit:FindFirstAncestorWhichIsA("Model"))
if Player then
if Player:IsInGroup(7104281) then -- Group ID
if hit.Name == "HumanoidRootPart" then
if ReadyToClaim == true then
local Coins = 1000
game.ReplicatedStorage.CoinGiver:FireServer(Coins)
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Come back in"
game.ReplicatedStorage.GiveChestData:FireServer(MinutesYouWantItToBe, SecondsYouWantItToBe, GroupHours)
repeat
ReadyToClaim = false
if GroupHours >= 1 then
if seconds <= 0 then
if minutes <= 0 then
GroupHours = GroupHours - 1
minutes = 59
seconds = 59
else
minutes = minutes - 1
seconds = 59
end
else
seconds = seconds - 1
end
else
if seconds <= 0 then
minutes = minutes - 1
seconds = 59
else
seconds = seconds - 1
end
end
if GroupHours <= 9 then
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring("").."0"..tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
else
if minutes <= 9 then
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":0"..tostring(minutes)..":"..tostring(seconds)
end
else
if seconds <= 9 then
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(GroupHours)..":"..tostring(minutes)..":"..tostring(seconds)
end
end
end
wait(1)
until GroupHours == 0 and minutes == 0 and seconds == 0
timer.Text = "claim your reward!"
game.Workspace.ChestModel.TimerPart.BillboardGui.ComeBackIn.Text = "Ready to"
ReadyToClaim = true
game.ReplicatedStorage.GiveGroupData:FireServer(minutes, seconds, GroupHours)
end
end
end
end
end)
Still doesnt work yet, i already finished made ‘Non Group’ chest,where if player touch part,the counter start,but in this(Group chest) i touched the part,but the counter doenst start yet,and also there no error in output
I just copy pasted you code and tried my best to get the code to what we were saying to do, grabbing the player character with hit:FindFirstAncestor… then the if Player then
I could have messed up when typing it because I did it in the editor here on the forum so you may want to double check it.